Using the special method push
,
you can add elements to the end of an array.
Let's see how it's done. Let's say we have
the following array:
let arr = [];
Add three elements to its end:
arr.push('a');
arr.push('b');
arr.push('c');
Let's see what happened:
console.log(arr); // shows ['a', 'b', 'c']
Fill an array with numbers 1
,
2
and 3
.
Let such an array be given:
let arr = [1, 2, 3];
Add the elements 4
and
5
to its end.