javascript - js native map
过去多啦不再A梦
过去多啦不再A梦 2017-05-19 10:44:23
0
3
481
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]

过去多啦不再A梦
过去多啦不再A梦

reply all(3)
洪涛
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.

曾经蜡笔没有小新

is the output....

a = [2,4,6]
洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template