What is the result of the following code snippet? const arr = [1, 2, 3]; const newArr = […arr, 4]; console.log(newArr.length);

Web Development Medium

Web Development — Medium

What is the result of the following code snippet? const arr = [1, 2, 3]; const newArr = […arr, 4]; console.log(newArr.length);

Key points

  • Spread operator creates a shallow copy
  • Array literals can combine spread elements with new values
  • Length property counts total elements in an array

Ready to go further?

Related questions