search

Home  >  Q&A  >  body text

javascript - js native map

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梦2764 days ago487

reply all(3)I'll reply

  • PHP中文网

    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.

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:46:23

    is the output....

    a = [2,4,6]

    reply
    0
  • PHP中文网

    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.

    reply
    0
  • Cancelreply