JAVASCRIPT · ОСНОВЫ · LESSON 15

Add to the list

push · about 12 minutes

Learning with progressRead the summary for free. To save the work, log in to the account.
STEP 1

The list can grow.

push adds a new element to the end of the array.

const pets = ["кот"];
pets.push("пёс");

✦ Now there are two pets.

STEP 2

Check the last element.

Once added, length will increase. A new element will appear at the end.

const pets = ["кот"];
pets.push("пёс");
console.log(pets.length);

✦ It's 2.

IN-CLASS PRACTICE

Type the code yourself

Type an example manually. Check the names, brackets and signs.

const colors = ["красный"];
colors.push("синий");
console.log(colors.length);
Open the editor for class work
HOMEWORK

Solve it yourself

Create const colors as an array with the word «красный». Add «синий» and «зелёный» via push, then output the array length.

The answer is hidden. Use similar examples from the lesson notes.

Opening up your homework