Accessing Array Elements in JavaScript
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:
javascriptlet arr = ['a', 'b', 'c'];
Let's display its elements:
javascriptconsole.log(arr[0]); // shows 'a'
console.log(arr[1]); // shows 'b'
console.log(arr[2]); // shows 'c'
Задание 1
Create an array with elements 1,
2, 3. Display each of
these elements on the screen.
Задание 2
Given the following array:
javascriptlet arr = [1, 2, 3];
Display each of its elements.
Задание 3
Given the following array:
javascriptlet arr = [1, 2, 3];
Display the sum of the elements of this array on the screen.
Задание 4
Given the following array:
javascriptlet arr = ['a', 'b', 'c', 'd'];
Use this array to output the following string:
javascript'a+b+c+d'