博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
dojo 学习日记 之 数组操作
阅读量:4358 次
发布时间:2019-06-07

本文共 3737 字,大约阅读时间需要 12 分钟。

dojo 对Javascript1.6 的数组操作功能进行了拓展:

  • ()
  • (arr, callback, thisObject) Determines whether or not every item in arr satisfies the condition implemented by callback.
  • (arr, callback, thisObject) Returns a new Array with those items from arr that match the condition implemented by callback.
  • (arr, callback, thisObject) for every item in arr, callback is invoked.
  • (arr, value, fromIndex, findLast) locates the first index of the provided value in the passed array.
  • (arr, value, fromIndex) locates the last index of the provided value in the passed array.
  • (arr, callback, thisObject, Ctr) applies callback to each element of arr and returns an Array with the results
  • (arr, callback, thisObject) Determines whether or not any item in arr satisfies the condition implemented by callback.

 

1.every(arr,callback,thisObject);   校验是否数组arr内的所有元素都满足回调函数的条件,是返回true

Parameter

Type

Description

arr

Array | String

用来迭代的数组. 如果是string,则对string的没资格字符操作

callback

Function | String

回调函数被触发,三个参数: item, index, and array ,如果条件满足,返回为true

thisObject

Object

可选 可能作为回调函数的作用域

// returns falsearray.every([1, 2, 3, 4], function(item){ return item>1; });// returns truearray.every([1, 2, 3, 4], function(item){ return item>0; });

 

2.(arr, callback, thisObject) ; 返回一个满足过滤条件元素组成的数组

Parameter

Type

Description

arr

Array

the array to iterate over.

callback

Function | String

a function that is invoked with three arguments (item, index, array). The return of this function is expected to be a boolean which determines whether the passed-in item will be included in the returned array.

thisObject

Object

Optional

may be used to scope the call to callback

// Example// returns [2, 3, 4]array.filter([1, 2, 3, 4], function(item){ return item>1; });

 

3.(arr, callback, thisObject) 对arr 的每一个元素,触发回调函数

// log out all members of the array:array.forEach([ "thinger", "blah", "howdy", 10 ],function(item){console.log(item);});// log out the members and their indexesarray.forEach([ "thinger", "blah", "howdy", 10 ],function(item, idx, arr){console.log(item, "at index:", idx);});// use a scoped object member as the callback var obj = {prefix: "logged via obj.callback:",callback: function(item){console.log(this.prefix, item);}};// specifying the scope function executes the callback in that scopearray.forEach([ "thinger", "blah", "howdy", 10 ],obj.callback,obj);
// alternately, we can accomplish the same thing with lang.hitch()array.forEach([ "thinger", "blah", "howdy", 10 ],lang.hitch(obj, "callback"));

 

4.(arr, value, fromIndex, findLast) 从fromIndex 起,返回arr数组中第一次出现value的索引值.

Parameter

Type

Description

arr

Array

 

value

Object

 

fromIndex

Integer

Optional

findLast

Boolean

Optional

Makes indexOf() work like lastIndexOf(). Used internally; not meant for external usage.

 

5.(arr, callback, thisObject, Ctr) 根据回调函数映射数组值

Parameter

Type

Description

arr

Array | String

the array to iterate on. If a string, operates on individual characters.

callback

Function | String

a function is invoked with three arguments, (item, index, array), and returns a value

thisObject

Object

Optional

may be used to scope the call to callback

Ctr

undefined

 
// returns [2, 3, 4, 5]array.map([1, 2, 3, 4], function(item){ return item+1 });

 

6.(arr, callback, thisObject)  检验数组里是否有满足回调函数条件,有则返回true

Parameter

Type

Description

arr

Array | String

the array to iterate over. If a string, operates on individual characters.

callback

Function | String

a function is invoked with three arguments: item, index, and array and returns true if the condition is met.

thisObject

Object

Optional

may be used to scope the call to callback

// is truearray.some([1, 2, 3, 4], function(item){ return item>1; });// is falsearray.some([1, 2, 3, 4], function(item){ return item<1; });

转载于:https://www.cnblogs.com/louluan/p/3404539.html

你可能感兴趣的文章
cms项目技术心得!
查看>>
Django模板系统
查看>>
位(Bit)与字节(Byte)
查看>>
关于两次指针(struct型)传参数的问题
查看>>
在Logstash的配置文件中对日志事件进行区分
查看>>
字符串之strcmp
查看>>
Lombok : 让你写 Java代码像C#一样爽
查看>>
《人件》读后感 PB16110698 第十周(~5.15)
查看>>
python 学习笔记十六 django深入学习一 路由系统,模板,admin,数据库操作
查看>>
Android使用Fragment程序崩溃
查看>>
codevs 2822 爱在心中(强连通分量)
查看>>
七:python 对象类型详解三:列表
查看>>
c语言基本数据类型相关
查看>>
SQL Server DATEADD() 函数
查看>>
makefile中的wildcard和patsubst
查看>>
F#基础教程 mutable关键字
查看>>
完全卸载MySQL数据库
查看>>
C#总结项目《影院售票系统》编写总结一
查看>>
Failed to stop iptables.service: Unit iptables.service not loaded.
查看>>
madpaly 移植到 TQ2440 遇到问题madplay not found (2)
查看>>