Put in order · JavaScript and TypeScript course · Module 2: Functions, Arrays and Objects

Array Basics - Steps to Add an Element

Arrange the steps of adding a new dinosaur species to an array in JavaScript:

Items to put in order

  • Add element: species.push(newDino)
  • Check the result: console.log(species.length)
  • Declare an array: const species = ['T-Rex']
  • Prepare a new value: const newDino = 'Velociraptor'
Show the answer

Correct order:

  1. Declare an array: const species = ['T-Rex']
  2. Prepare a new value: const newDino = 'Velociraptor'
  3. Add element: species.push(newDino)
  4. Check the result: console.log(species.length)