1.

What Will Be The Output Of The Code Below? var Trees = ["xyz","xxxx","test","ryan","apple"]; delete Trees[3]; console.log(trees.length);

Answer»

The output would be 5. When we use the DELETE operator to delete an array element, the array length is not affected from this. This holds even if you deleted all elements of an array using the delete operator.

In other WORDS, when the delete operator removes an array element, that deleted element is not longer present in array. In PLACE of value at deleted index UNDEFINED x 1 in chrome and undefined is placed at the index. If you do console.log(trees) output ["xyz", "xxxx", "test", undefined × 1, "apple"] in Chrome and in Firefox ["xyz", "xxxx", "test", undefined, "apple"].

The output would be 5. When we use the delete operator to delete an array element, the array length is not affected from this. This holds even if you deleted all elements of an array using the delete operator.

In other words, when the delete operator removes an array element, that deleted element is not longer present in array. In place of value at deleted index undefined x 1 in chrome and undefined is placed at the index. If you do console.log(trees) output ["xyz", "xxxx", "test", undefined × 1, "apple"] in Chrome and in Firefox ["xyz", "xxxx", "test", undefined, "apple"].



Discussion

No Comment Found