Super simple function:
function reindex_array_keys(array, start){
var temp = [];
start = typeof start == 'undefined' ? 0 : start;
start = typeof start != 'number' ? 0 : start;
for(var i in array){
temp[start++] = array[i];
}
return temp;
}
testArray = reindex_array_keys(testArray);
Note: this will blow away any custom keys. the result will always be numerically indexed. you could add in checks for if it's an array or not but i tend to just not use functions i build other than they are intended to be used. you can also start the index higher if you like:
testArray = reindex_array_keys(testArray, 3);
which will produce 3 'undefined' items at the beginning of the array. you can then add to it later but i think it would be better to do testArray.unshift('newValue')
first then reindex personally.
have fun
.join()
will result in the commas. you need at least single quotes (.join('')
), but that will put the results right next to each other