Accessing the elements of an array is
similar to accessing the characters of
a string. Each element of the array has
its own index: the first element has the
index 0
, the second has the
index 1
, and so on. These indices
are called also keys of the array
elements. Let's look at an example.
Let's say we have the following array:
let arr = ['a', 'b', 'c'];
Let's display its elements:
console.log(arr[0]); // shows 'a'
console.log(arr[1]); // shows 'b'
console.log(arr[2]); // shows 'c'
Create an array with elements 1
,
2
, 3
. Display each of
these elements on the screen.
Given the following array:
let arr = [1, 2, 3];
Display each of its elements.
Given the following array:
let arr = [1, 2, 3];
Display the sum of the elements of this array on the screen.
Given the following array:
let arr = ['a', 'b', 'c', 'd'];
Use this array to output the following string:
'a+b+c+d'