Array Access in JavaScript

Level 257 keystrokes

This creates an array and outputs the first element 'apple'.

JavaScript code

// Arrays are created with square brackets []
// Elements are separated by commas
1let fruits = ["apple", "banana"];
// Array indices start at 0, not 1
// fruits[0] is "apple", fruits[1] is "banana"
2console.log(fruits[0]);

Output

apple
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • "× 4
  • ;× 2
  • [× 2
  • ]× 2
  • ,× 1
  • .× 1
  • (× 1
  • )× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice