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

JavaScript Array Basics Guide

JavaScript arrays are ordered collections that can hold various data types and are accessed using zero-based indexing. Key operations include updating elements, using common methods like push() and pop(), and destructuring for value assignment. Two-dimensional arrays are arrays of arrays, useful for grid-like data representation.

Uploaded by

kritesh
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)
2 views2 pages

JavaScript Array Basics Guide

JavaScript arrays are ordered collections that can hold various data types and are accessed using zero-based indexing. Key operations include updating elements, using common methods like push() and pop(), and destructuring for value assignment. Two-dimensional arrays are arrays of arrays, useful for grid-like data representation.

Uploaded by

kritesh
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

JavaScript Array Basics Cheat Sheet

What is an Array?

JavaScript arrays are ordered collections of values accessible by numeric indices. They can store multiple data types
including numbers, strings, booleans, objects, and other arrays.

Accessing Elements

Use square brackets and zero-based indexing:


array[0] // first item
array[10] // undefined if out of bounds

Array Properties

[Link] returns the number of elements.

Updating Elements

array[index] = newValue; // Updates element at index

Two-Dimensional Arrays

An array of arrays, used for grid-like data:


array[row][col]

Destructuring Arrays

[a, b] = array; // Assigns values


[a, b, ...rest] = array; // Collects remaining items

Common Methods

push() - Add to end


pop() - Remove from end
shift() - Remove from start
unshift() - Add to start
indexOf() - Find index
splice() - Add/remove at index
includes() - Check existence
concat() - Merge arrays
slice() - Copy a portion
reverse() - Reverse in place
join() - Join into string
split() - String to array
spread (...) - Copy or expand

Spread Syntax
JavaScript Array Basics Cheat Sheet

[...arr] creates a shallow copy of an array.

Example

const fruits = ['apple', 'banana'];


[Link]('mango');
[Link](fruits); // ['apple', 'banana', 'mango']

You might also like