在数组 arr 中,查找值与 item 相等的元素出现的所有位置

使用forEach方法进行书写

1 function findAllOccurrences(arr, target) 
2  {var result=[];
3  arr.forEach(function(item,index){  
4   if(item==target){     
5      result.push(index);
6  }

 

posted @ 2020-06-17 13:56  颜若笑叻  阅读(424)  评论(0)    收藏  举报