How to append elements to the end of an array in JavaScript

2 Answers

0 votes
let arr = [9, 7, 2, 8];

arr.push(3);
arr.push(0);

console.log(arr);
console.log(arr.length);



/*
run:

[9, 7, 2, 8, 3, 0] 

6

*/

 



answered Aug 29, 2020 by avibootz
0 votes
let arr = [];

arr.push(3);
arr.push(0);
arr.push(9);
arr.push(4);

console.log(arr);
console.log(arr.length);



/*
run:

[3, 0, 9, 4] 

4

*/

 



answered Aug 29, 2020 by avibootz
...