Home >Web Front-end >JS Tutorial >Share an example code that uses js to filter repeated elements in an array
This article mainly introduces javascriptFilteringArrayRelated information on the implementation method of repeated elements. Friends in need can refer to
javascript filtering Implementation method of repeated elements in array
The following is the information found on the Internet, which can be used directly in the project. You can refer to it:
Implementation code:
function filterArray(receiveArray){ var arrResult = new Array(); //定义一个返回结果数组. for (var i=0; i<receiveArray.length; ++i) { if(check(arrResult,receiveArray[i]) == -1) { //在这里做i元素与所有判断相同与否 arrResult.push(receiveArray[i]); // 添加该元素到新数组。如果if内判断为false(即已添加过), //则不添加。 } } return arrResult; } function check(receiveArray,checkItem){ var index = -1; // 函数返回值用于布尔判断 for(var i=0; i<receiveArray.length; ++i){ if(receiveArray[i]==checkItem){ index = i; break; } } return index; }
[Related recommendations]
1. Free js online video tutorial
2. JavaScript Chinese Reference Manual
3. php.cn Dugu Jiujian (3) - JavaScript video tutorial
The above is the detailed content of Share an example code that uses js to filter repeated elements in an array. For more information, please follow other related articles on the PHP Chinese website!