Guest User

Untitled

a guest
May 20th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. 先来看一个例子
  2.  
  3. ```
  4. var Arr = [100, 200, 300, 400, 500]
  5. function fn (arr) {
  6. arr.forEach(function(item, index, array){
  7. if(item == 300) {
  8. return index;
  9. console.log(index);
  10. }
  11. console.log(index);
  12. })
  13. }
  14. var index = fn(Arr);
  15. console.log(index);
  16.  
  17. // 输出结果如下:
  18. 0
  19. 1
  20. 3
  21. 4
  22. undefined
  23. ```
  24.  
  25. 有没有觉得很奇怪,
  26.  
  27. forEach无法在所有元素都传递给调用的函数之前终止
Add Comment
Please, Sign In to add comment