How does Array.prototype.sort handle undefined values ββin an array?
var array = [1,undefined,2,undefined,3,undefined,4]; var array2 = []; array2[0] = 1;array2[2] = 2;array2[4] = 3;array2[6] = 4;
When calling array.sort(function(l,r) { ... }); Undefined values ββare never passed as l or r .
Can I guarantee that all undefined values ββwill always go to the end of the array for all browsers?
Will the next loop process all data not undefined in the array
array.sort(); for (var i = 0; array[i] !== undefined; i++) {
You can assume that no one declared undefined as a variable.
Raynos
source share