DEV Community

antony stark
antony stark

Posted on

Array and their methods in javascript

what is a array in javascript
An Array is an object type designed for storing data collections.

Key characteristics of JavaScript arrays are:

  • Elements: An array is a list of values, known as elements.
  • Ordered: Array elements are ordered based on their index.
  • Zero indexed: The first element is at index 0, the second at index 1, and so on.
  • Dynamic size: Arrays can grow or shrink as elements are added or removed.
  • Heterogeneous: Arrays can store elements of different data types (numbers, strings, objects and other arrays). Example
const cars = ["Honda", "Lamborghini", "BMW"];
Enter fullscreen mode Exit fullscreen mode

Array methods:-

  • array length The length method returns the length or size of an array example
const fruits = ["Banana", "Orange", "Apple", "Mango"];

let size = fruits.length;
Enter fullscreen mode Exit fullscreen mode
  • Pop method the pop() method is used to remove one element from the end of the array Example
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();
Enter fullscreen mode Exit fullscreen mode
  • Push method The push() method adds a new element to an array at the end: Example:-
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
Enter fullscreen mode Exit fullscreen mode

Top comments (0)