dojo 对Javascript1.6 的数组操作功能进行了拓展:
- clearCache()
- every(arr,callback,thisObject) Determines whether or not every item in arr satisfies the condition implemented by callback.
- filter(arr,thisObject) Returns a new Array with those items from arr that match the condition implemented by callback.
- forEach(arr,thisObject) for every item in arr,callback is invoked.
- indexOf(arr,value,fromIndex,findLast) locates the first index of the provided value in the passed array.
- lastIndexOf(arr,fromIndex) locates the last index of the provided value in the passed array.
- map(arr,thisObject,Ctr) applies callback to each element of arr and returns an Array with the results
- some(arr,thisObject) Determines whether or not any item in arr satisfies the condition implemented by callback.
1.every(arr,thisObject); 校验是否数组arr内的所有元素都满足回调函数的条件,是返回true
Parameter @H_403_32@ | Type @H_403_32@ | Description @H_403_32@ |
arr @H_403_32@ | Array | String @H_403_32@ | 用来迭代的数组. 如果是string,则对string的没资格字符操作 @H_403_32@ |
callback @H_403_32@ | Function | String @H_403_32@ | 回调函数被触发,三个参数: item,index,and array ,如果条件满足,返回为true @H_403_32@ |
thisObject @H_403_32@ | Object @H_403_32@ | 可选 可能作为回调函数的作用域 @H_403_32@ |
// returns false array.every([1,2,3,4],function(item){ return item>1; }); // returns true array.every([1,function(item){ return item>0; });
2.filter(arr,thisObject) ; 返回一个满足过滤条件元素组成的数组
Parameter @H_403_32@ | Type @H_403_32@ | Description @H_403_32@ |
arr @H_403_32@ | Array @H_403_32@ | the array to iterate over. @H_403_32@ |
callback @H_403_32@ | Function | String @H_403_32@ | a function that is invoked with three arguments (item,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. @H_403_32@ |
thisObject @H_403_32@ | Object @H_403_32@ | Optional may be used to scope the call to callback @H_403_32@ |
// Example // returns [2,4] array.filter([1,function(item){ return item>1; });
3.forEach(arr,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 indexes array.forEach( [ "thinger",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 scope array.forEach( [ "thinger",obj.callback,obj );
// alternately,we can accomplish the same thing with lang.hitch() array.forEach( [ "thinger",lang.hitch(obj,"callback") );
4.indexOf(arr,findLast) 从fromIndex 起,返回arr数组中第一次出现value的索引值.
Parameter @H_403_32@ | Type @H_403_32@ | Description @H_403_32@ |
arr @H_403_32@ | Array @H_403_32@ | @H_403_32@ |
value @H_403_32@ | Object @H_403_32@ | @H_403_32@ |
fromIndex @H_403_32@ | Integer @H_403_32@ | Optional @H_403_32@ |
findLast @H_403_32@ | Boolean @H_403_32@ | Optional Makes indexOf() work like lastIndexOf(). Used internally; not meant for external usage. @H_403_32@ |
5.@L_502_11@(arr,Ctr) 根据回调函数映射数组值
Parameter @H_403_32@ | Type @H_403_32@ | Description @H_403_32@ |
arr @H_403_32@ | Array | String @H_403_32@ | the array to iterate on. If a string,operates on individual characters. @H_403_32@ |
callback @H_403_32@ | Function | String @H_403_32@ | a function is invoked with three arguments,(item,array),and returns a value @H_403_32@ |
thisObject @H_403_32@ | Object @H_403_32@ | Optional may be used to scope the call to callback @H_403_32@ |
Ctr @H_403_32@ | undefined @H_403_32@ | @H_403_32@ |
// returns [2,4,5] array.map([1,function(item){ return item+1 });
6.some(arr,thisObject) 检验数组里是否有满足回调函数条件,有则返回true
Parameter @H_403_32@ | Type @H_403_32@ | Description @H_403_32@ |
arr @H_403_32@ | Array | String @H_403_32@ | the array to iterate over. If a string,operates on individual characters. @H_403_32@ |
callback @H_403_32@ | Function | String @H_403_32@ | a function is invoked with three arguments: item,and array and returns true if the condition is met. @H_403_32@ |
thisObject @H_403_32@ | Object @H_403_32@ | Optional may be used to scope the call to callback @H_403_32@ |
// is true array.some([1,function(item){ return item>1; }); // is false array.some([1,function(item){ return item<1; });