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:
- Declare an array: const species = ['T-Rex']
- Prepare a new value: const newDino = 'Velociraptor'
- Add element: species.push(newDino)
- Check the result: console.log(species.length)