Javascript Array forEach() Method
来源:互联网 发布:更改数据库名称 编辑:程序博客网 时间:2024/05/22 09:44
Description:
Javascript array forEach() method calls a function for each element in the array.
Syntax:
array.forEach(callback[, thisObject]);
Here is the detail of parameters:
callback : Function to test each element of the array.
thisObject : Object to use as this when executing callback.
Return Value:
Returns created array.
Compatibility:
This method is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. To make it work you need to add following code at the top of your script:
if (!Array.prototype.forEach){ Array.prototype.forEach = function(fun /*, thisp*/) { var len = this.length; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) fun.call(thisp, this[i], i, this); } };}
<html><head><title>JavaScript Array forEach Method</title></head><body><script type="text/javascript">if (!Array.prototype.forEach){ Array.prototype.forEach = function(fun /*, thisp*/) { var len = this.length; if (typeof fun != "function") throw new TypeError(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) fun.call(thisp, this[i], i, this); } };}function printBr(element, index, array) { document.write("<br />[" + index + "] is " + element ); }[12, 5, 8, 130, 44].forEach(printBr); </script></body></html>
[0] is 12[1] is 5[2] is 8[3] is 130[4] is 44
reference:
http://www.tutorialspoint.com/javascript/array_foreach.htm
0 0
- Javascript Array forEach() Method
- Javascript数组Array的forEach扩展方法
- Javascript数组Array的forEach方法
- JavaScript 中 Array.forEach方法使用注意事项
- javascript array.forEach()和array.map()的区别
- Parallel's foreach method
- ForEach Method in Java8
- java8中ForEach Method
- java8中ForEach Method
- javascript foreach
- javascript foreach
- javascript forEach、
- 数据库array制表foreach()
- foreach()And array() Function
- Array.prototype.filter()+forEach()
- javaScript随机生成一个5位以内的数,及数组对象Array原型forEach解析
- Javascript Array forEach()中无法return和break,代替方法some()与every()
- javascript method
- 匈牙利算法模板题 hdu 1150
- 如何设计一套第三方框架
- Swift 学习小结:简单值 及流程控制
- 左偏树模板
- 【菜鸟学Opencv 2】VisualStudio2010配置OpenCV的快速方法(适用于vs2013)
- Javascript Array forEach() Method
- Yii2 数据操作DAO
- Hibernate操作oracle的demo,报错
- Codeforces Round #292 (Div. 1)
- 删除表中某字段重复的记录(只保留一条)
- 重写ImageView使用Xfermode遮罩实现圆角和圆形
- 第二章 Big O notation 进阶课程
- autolayout 心得
- UVA 11795-Mega Man’s Mission(状态压缩DP)