80.1k views
5 votes
What does the delete keyword do to the element of an array? (delete array[3])

A. Removes the element and leaves it undefined
B. Sets the element to null
C. Shifts all elements to the left to fill the gap
D. Throws an error and does not affect the array

1 Answer

3 votes

Final answer:

The delete keyword sets the array element at the specified index to undefined without altering the length of the array, leaving a 'hole'.

Step-by-step explanation:

When you use the delete keyword on an element of an array in JavaScript, such as with delete array[3], it does not actually remove the element. Instead, it sets the specific element to undefined. This means that the length of the array will not change, but the value of the element at the specified index will be undefined. The delete keyword does not shift other elements to fill the gap left by the deleted element, so there will be a 'hole' in the array.

User Greduan
by
8.1k points