I want to remove all of 0, false, undefined and "" elements in my list.
Here is my code:
var a = [ 1232, "fesr", undefined,undefined, true, 0, false ,'',false , false , undefined]
console.log(a);
for(var i=0 ; i < a.length ; i++){
if(a[i]===0 || a[i]===false || a[i]==='' || a[i]===undefined ){
a.splice(i,2)
}else{
continue
}
}
console.log(a);
input :
[ 1232, "fesr", undefined,undefined, true, 0, false ,'',false , false , undefined]
output:
[ 1232, "fesr", true, "", undefined ]
As you see first my code does not remove "" .
second problem is it does not remove all of 0, false and undefined elements if we have a greater number of them!
How can i solve that?