What is an Array?
An array is a variable that can hold more than one value, it can store data with different data types such as string, numbers, boolean and object.
JavaScript arrays come equipped with a set of built-in functions known as methods, enabling developers to perform various actions on array values.
Let's take a quick tour of some common array methods and their functionalities:
-
.shift()
This method removes the first element from the array and returns the removed element. -
.unshift()
It adds an element at the beginning of an array and returns a new length of the array. -
.pop()
This method removes the last element from the array and returns a new length of the array. -
.push()
Adds one or more elements to the end of the array and returns the new length of the array. -
.reverse()
This method changes the order of the elements in the array, turning the first element into the last. It returns the reversed array. -
.sort()
This method sort the elements of the array in order of ascending, starting with the smallest value to the largest. It returns the sorted array.
While the explanations provide a solid foundation, nothing beats hands-on experience. Experimenting with these array methods in the provided playground will solidify your understanding and pave the way for practical application in your projects.
Here are a few links that can help you learn more about Arrays W3schools, javascript.info & MDN Web.