JavaScript中forEach如何安全跳出循环?
- 内容介绍
- 文章标签
- 相关推荐
本文共计621个文字,预计阅读时间需要3分钟。
定义和用法:使用 `forEach` 方法遍历数组中的每个元素,并将每个元素传递给回调函数。
示例:javascriptarray.forEach(function(currentValue, index, arr), thisValue);
forEach() 调用数组的每个元素,并将元素传递给回调函数。
注意: forEach() 对于空数组是不会执行回调函数的。
用法:
array.forEach(function(currentValue, index, arr), thisValue)
1==> currentValue 必需。当前元素
2==> index 可选。当前元素的索引值,是数字类型的
3==> arr 可选。当前元素所属的数组对象
4==> 可选。传递给函数的值一般用 "this" 值。
如果这个参数为空, "undefined" 会传递给 "this" 值
forEach 的注意点
forEach() 本身是不支持的 continue 与 break 语句的。
本文共计621个文字,预计阅读时间需要3分钟。
定义和用法:使用 `forEach` 方法遍历数组中的每个元素,并将每个元素传递给回调函数。
示例:javascriptarray.forEach(function(currentValue, index, arr), thisValue);
forEach() 调用数组的每个元素,并将元素传递给回调函数。
注意: forEach() 对于空数组是不会执行回调函数的。
用法:
array.forEach(function(currentValue, index, arr), thisValue)
1==> currentValue 必需。当前元素
2==> index 可选。当前元素的索引值,是数字类型的
3==> arr 可选。当前元素所属的数组对象
4==> 可选。传递给函数的值一般用 "this" 值。
如果这个参数为空, "undefined" 会传递给 "this" 值
forEach 的注意点
forEach() 本身是不支持的 continue 与 break 语句的。

