Home >Web Front-end >HTML Tutorial >Array filter method to filter array elements

Array filter method to filter array elements

小云云
小云云Original
2018-03-21 09:32:463189browse

This article mainly shares with you how Array.prototype.filter filters elements in an array. I hope it can help you.

/**
 * @method reduce
 * @param {number}   item   当前迭代的数组元素
 * @param {number}   index  当前迭代的数组元素下下标
 * @param {array}    array  原数组
 */
  let arr = [1,2,6,3,4,5];
  let res = arr.filter(function(item,index,array){      //元素值,元素的索引,原数组。
      return (item>3);
  });
  console.log(res);//[6, 4, 5]

The filter method can remove elements that do not match the array and return a new array.

The above is the detailed content of Array filter method to filter array elements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn