Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Changing Elements

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”;

JavaScript Array length

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”;

JavaScript Array delete()

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];