unshift
Add an element to the front of an array.
You might have an array with 3 numbers, like 1, 2, and 3. If you want to add another number to the front, then you unshift it into the array. You do it like this:
let thoseNumbers = [1, 2, 3];
let head = 0;
head = thoseNumbers.unshift(0);
Parameters
- item: the element to add to the front of the array.
Example
Make an array that simulates a train. Place the parts of the train in the right order.