Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 先来看一个例子
- ```
- var Arr = [100, 200, 300, 400, 500]
- function fn (arr) {
- arr.forEach(function(item, index, array){
- if(item == 300) {
- return index;
- console.log(index);
- }
- console.log(index);
- })
- }
- var index = fn(Arr);
- console.log(index);
- // 输出结果如下:
- 0
- 1
- 3
- 4
- undefined
- ```
- 有没有觉得很奇怪,
- forEach无法在所有元素都传递给调用的函数之前终止
Add Comment
Please, Sign In to add comment