Advertisement
apl-mhd

array with call back

Apr 26th, 2021
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var arr = [1,2,3,4]
  2.  
  3.  
  4. // arr.forEach(function(value, index, arr){
  5.  
  6.  
  7. //     console.log(index, value, arr)
  8. // })
  9.  
  10.  
  11.  
  12. function forEach(arr, func){
  13.  
  14.     for(var i = 0; i<=arr.length; i++){
  15.         func(i,arr);
  16.  
  17.     }
  18. }
  19.  
  20. var sum=0;
  21.  
  22. forEach(arr, function(i, arr){
  23.    console.log(i,arr);
  24.     sum += i;
  25. });
  26.  
  27. console.log(sum)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement