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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -