javascript find first element of array
const array = [1,2,3,4,5]; const firstElement = array.shift(); // array -> [2,3,4,5] // firstElement -> 1
Here is what the above code is Doing:
1. We create an array with 5 elements.
2. We call the shift() method on the array.
3. The shift() method removes the first element from the array and returns it.
4. We store the returned value in a variable called firstElement.
5. We log the value of firstElement to the console.