Home > Article > Web Front-end > Array filter method to filter array elements
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!