Array elements are retrieved by their index numbers.
Array indexing begins with 0: [0] represents the first array element. [1] represents the second. [2] represents the third, and so on. |
Example
const fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits[0] = “Kiwi”; |
The length property offers a convenient method for adding a new element to the end of an array.
Example
const fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; fruits[fruits.length] = “Kiwi”; |
Caution! Utilizing delete() leaves undefined gaps in the array. Consider using pop() or shift() instead. |
Example
const fruits = [“Banana”, “Orange”, “Apple”, “Mango”]; delete fruits[0]; |