javascript - construct a new array from an array by filtering out null items -
i trying construct array looping on array more or less looks this
var x = [1, null, 324, 110, null] i trying loop on , check if item @ index not null goes new array
var numbercollection = []; for(var = 0; < x.length; i++){ numbercollection[i] = (!!x[i]) ? x[i]; } console.log(numbercollection) which not work. missing? saw examples of deleting invalid item array out of scope in context
try this,
for(var = 0; < x.length; i++){ if (x[i] !== null){ numbercollection.push(x[i]); } }
Comments
Post a Comment