Properties and methods in Array
Published by: Anil K. Panta
Properties and methods
Arrays have their own built-in variables and functions, also known as properties and methods. Here are some of the most common ones.
length
An array’s length property stores the number of elements inside the array.
Example
["a", "b", "c", 1, 2, 3].length;
Output
6
concat
An array’s concat method returns a new array that combines the values of two arrays.
Example
["tortilla chips"].concat(["salsa", "queso", "guacamole"]);
Output
["tortilla chips", "salsa", "queso", "guacamole"]
pop
An array’s pop method removes the last element in the array and returns that element’s value.
Example
["Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"].pop();
Output
“Pluto”
push
An array’s push method adds an element to the array and returns the array’s length.
Example
["John", "Kate"].push(8);
Output
3
reverse
Example
["a", "b", "c"].reverse();
Output
["c", "b", "a"]