0% found this document useful (0 votes)
5 views2 pages

JavaScript Array Properties and Methods

Uploaded by

Malathi N
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

JavaScript Array Properties and Methods

Uploaded by

Malathi N
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cheatsheets / Learn JavaScript

Arrays

Property .length

The .length property of a JavaScript array indicates const numbers = [1, 2, 3, 4];
the number of elements the array contains.

[Link] // 4

Index

Array elements are arranged by index values, starting at // Accessing an array element
0 as the first element index. Elements can be accessed
const myArray = [100, 200, 300];
by their index using the array name, and the index
surrounded by square brackets.
[Link](myArray[0]); // 100
[Link](myArray[1]); // 200
[Link](myArray[2]); // 300

Method .push()

The .push() method of JavaScript arrays can be // Adding a single element:


used to add one or more elements to the end of an array.
const cart = ['apple', 'orange'];
.push() mutates the original array and returns the
new length of the array. [Link]('pear');

// Adding multiple elements:


const numbers = [1, 2];
[Link](3, 4, 5);
Method .pop()

The .pop() method removes the last element from const ingredients = ['eggs', 'flour',
an array and returns that element.
'chocolate'];

const poppedIngredient =
[Link](); // 'chocolate'
[Link](ingredients); // ['eggs',
'flour']

Mutable

JavaScript arrays are mutable, meaning that the values const names = ['Alice', 'Bob'];
they contain can be changed.
Even if they are declared using const , the contents
can be manipulated by reassigning internal values or using [Link]('Carl');
methods like .push() and .pop() . // ['Alice', 'Bob', 'Carl']

Arrays

Arrays are lists of ordered, stored data. They can hold // An array containing numbers
items that are of any data type. Arrays are created by
const numberArray = [0, 1, 2, 3];
using square brackets, with individual elements separated
by commas.
// An array containing different data
types
const mixedArray = [1, 'chicken', false];

Print Share

You might also like