Array Spread in JavaScript

Level 269 keystrokes

The spread operator (...) expands array elements into individual elements.

JavaScript code

// Create first array with elements 1 and 2
1let a = [1, 2];
// Create second array with elements 3 and 4
2let b = [3, 4];
// Use spread operator to combine both arrays
// ...a expands to 1, 2 and ...b expands to 3, 4
3let c = [...a, ...b];
// Print the combined array
4console.log(c);

Output

[ 1, 2, 3, 4 ]
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.

  • .× 7
  • ;× 4
  • ,× 3
  • [× 3
  • ]× 3
  • =× 3
  • (× 1
  • )× 1

More JavaScript examples at level 2

← JavaScript typing practice