Suppose I am a custom script developer and I have no control over the inline javascript. The page creates arrays with random lengths, filling them with random values (including false ones, for example undefined ). Not every element is assigned a value, so there may be empty slots.
Simplified example (Firefox console):
var arr = new Array(3); arr[0] = null; arr[1] = undefined; console.log(arr); \\ Array [ null, undefined, <1 empty slot> ] console.log(arr[1]); \\ undefined console.log(arr[2]); \\ undefined console.log(arr[1] === arr[2]); \\ true console.log(typeof arr[1]); \\ undefined console.log(typeof arr[2]); \\ undefined
As we can see, Firefox displays undefined and empty slots differently, whereas for javascript they seem the same.
Now suppose I want to clear such an array by removing all empty slots, but leaving the undefined elements intact. How to do it?
source share