I am learning ES6 and following is my ES5 code which is running fine -
var myArr = [34,45,67,34,2,67,1,5,90];
var evenArr = [];
var oddArr = [];
myArr.map(function(x){
if(x%2==0) evenArr.push(x);
else oddArr.push(x);
});
Now if I am converting this to ES6 I am getting errors of Unexpected token near if, let me know what I am doing wrong here -
My ES6 code -
var myArr = [34,45,67,34,2,67,1,5,90];
var evenArr = [];
var oddArr = [];
myArr.map( x => if(x%2==0) evenArr.push(x) else oddArr.push(x) )
{}if more than one statement. Seems you should be using forEach anyway, map creates a new array that you are throwing away.