I have a few arrays that are laid out like so:
var row1 = [4,6,4,0,9];
var row2 = [5,2,0,8,1];
var row3 = [2,0,3,1,6];
I want to replace any values that have 0 with a null value. so they would look like:
var row1 = [4,6,4,,9];
var row2 = [5,2,,8,1];
var row3 = [2,,3,1,6];
Any ideas? Basically what I'm trying to do is loop through each value of the array, check to see if it equals 0, and if so replace it with a null value.
Thanks in advance.
[4,6,4,,9]isn't valid. Did you mean[4,6,4,null,9]? I.E. maintain the.lengthproperty? Or did you want the 0s removed, leaving you with[4,6,4,9]?3 in array; // false.forEachskips element3too (whereas something like jQuery.each() does not). OP: are holes acceptable then? Answering it means the different betweendelete a[index]anda[index] = null, two semantically different things.