Array filter method to filter array elements

小云云
Release: 2018-03-21 09:32:46
Original
3132 people have browsed it

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]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!