Array Length in JavaScript

Level 253 keystrokes

This creates an array and outputs its length, which is 5.

JavaScript code

// Create an array with 5 numbers
1let nums = [1, 2, 3, 4, 5];
// The length property returns the number of elements
// It's a property, not a method, so no parentheses needed
// nums.length is 5
2console.log(nums.length);

Output

5
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
  • (× 1
  • )× 1
  • [× 1
  • ]× 1
  • =× 1

More JavaScript examples at level 2

← JavaScript typing practice