# Adding elements to array by keys JavaScript

Elements in an array don't need to be added immediately at the time of declaring this array. You can first declare this array, and then add the necessary elements to it, like this:

`let arr = []; arr[0] = 'a'; arr[1] = 'b'; arr[2] = 'c'; console.log(arr); // shows ['a', 'b', 'c']`

You can also add elements to an array already filled with data:

`let arr = ['a', 'b', 'c']; arr[3] = 'd'; console.log(arr); // shows ['a', 'b', 'c', 'd']`

Using the above technique, create an array with the elements `1`, `2` and `3`.

Let such an array be given:

`let arr = [1, 2, 3];`

Add the elements `4` and `5` to its end.

← →
↑
en ru