Back to Freecodecamp

Learn Arrays and Loops Lesson B

curriculum/challenges/english/blocks/top-learn-arrays-and-loops/661e27568602567c118451d2.md

latest814 B
Original Source

--description--

To access the elements of an array, you can use the index number. The index number starts from 0, so the first element of an array is at index 0, the second element is at index 1, and so on.

For example, to access the first element of the fruits array, you can use the following code:

javascript
const fruits = ['apple', 'banana', 'orange'];
console.log(fruits[0]); // Output: apple
console.log(fruits[2]); // Output: orange

If the index is out of range, JavaScript will return undefined. Meaning that if you try to access fruits[3] in the above example, it will return undefined.

--questions--

--text--

What is the element at the fourth index of the fruits array?

--answers--

orange


apple


pineapple


undefined

--video-solution--

4