js循环数组各种方法array 汇总-基础
这几天做系统, 又用到多维数组 循环 交叉。所以总结一套 以供参考记录
1. var myStringArray = ["Hello","World"];
2. for (var
3. alert(myStringArray[i]);
4. //Do something
5. }
1. Array.prototype.foo = "foo!";
2. var array = ['a', 'b', 'c'];
3.
4. for (var i in
5. alert(array[i]);
6. }
7.
8. for(var i in this.$GLOBAL_DETAIL.album_photo_ids){if(this.$GLOBAL_DETAIL.album_photo_ids[i] == "3487675024077108") alert(this.$GLOBAL_DETAIL.album_photo_ids[i]);}
1. [1,2,3,4].map( function(item) {
2. alert(item);
3. })
1. var x = [1,2,3,4].map( function(item) { return
2.
3. // And now x is [10,20,30,40]
1. var myStringArray = [ "Hello", "World"
2. var
3. for (var
4. if (i in
5. var
6. do something with
7. }
8. }
1. var myStringArray = [ "Hello", "World"
2. myStringArray.forEach( function(s) {
3. do something with
4. } )
1. var i=0,item,items = ['one','two','three'];
2. while(item=items[i++]){
3. console.log(item);
4. }
5.
6. // logs: 'one','two','three'
7.
8. and for
9. var items = ['one','two','three'], i=items.length;
10. while(i--){
11. console.log(items[i]);
12. }
13.
14. // logs: 'three','two','one'
15.
16. or the classical for
17. var items = ['one','two','three']
18. for(var
19. console.log(items[i]);
20. }
21.
22. // logs: 'one','two','three'
1. var myStringArray = ['Hello', 'World']; // array uses [] not {}
2. for (var i in
3. ' -> ' + myStringArray[i]); // i is the index/key, not the item
4. }
5.
6.
7.
8.
9.
10. 11. web前端入坑系列:点击标题进入
js循环数组各种方法array 汇总-基础
原创小北[机智] 博主文章分类:┈┈【JavaScript】 ©著作权
©著作权归作者所有:来自51CTO博客作者小北[机智]的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
javascript刷新父页面的各种方法汇总
javascript刷新父页面的各种方法汇总
javascript刷新父页面