var arr = [1,2,3,4,5,6];
var a = [];
a = arr.filter(function(i){
if(i%2 == 0){
return i
}
})
What is the first sensory output?
How to make it output [2,4,6]
PHP中文网2017-05-19 10:46:23
var arr = [1,2,3,4,5,6];
var a = [];
a = arr.filter(function(i){
return i % 2 == 0
});
console.log(a);
Filter accepts true and false, but does not accept the original value of your array.
PHP中文网2017-05-19 10:46:23
Execute the specified function (callback) once for each element in the array, and create a new array. This array element is the original array element that returns true when all callback functions are executed.