JavaScript Array Class

The Array class in JavaScript provides various methods and properties for working with arrays effectively. This tutorial covers the Array class in detail with its constructor, static methods, static properties, instance methods, and instance properties.

1 Constructor

ConstructorDescription
Array()Used to create a new array.

2 Static Methods

MethodDescription
Array.from()Creates a new array from an array-like or iterable object.
Array.fromAsync()Creates an array from an asynchronous iterable or array-like object.
Array.isArray()Checks if a value is an array.
Array.of()Creates a new array with a variable number of arguments.

3 Instance Methods

MethodDescription
at()Returns the element at the specified index.
concat()Merges two or more arrays.
copyWithin()Copies array elements within the array.
entries()Returns an iterator object containing key-value pairs.
every()Checks if all elements pass a test.
fill()Fills array elements with a static value.
filter()Creates a new array with elements that pass a test.
find()Finds the first element that satisfies a condition.
findIndex()Finds the index of the first element that satisfies a condition.
findLast()Finds the last element that satisfies a condition.
findLastIndex()Finds the index of the last element that satisfies a condition.
flat()Flattens nested arrays.
flatMap()Maps each element and flattens the result.
forEach()Executes a function for each array element.
includes()Checks if an array includes a value.
indexOf()Finds the first occurrence of a value.
join()Joins array elements into a string.
keys()Returns an iterator with keys of the array.
lastIndexOf()Finds the last occurrence of a value.
map()Creates a new array by applying a function to each element.
pop()Removes the last element and returns it.
push()Adds one or more elements to the end of the array.
reduce()Applies a function to reduce the array to a single value.
reduceRight()Applies a function from right to left to reduce the array.
reverse()Reverses the array elements.
shift()Removes the first element and returns it.
slice()Extracts a portion of the array into a new array.
some()Checks if at least one element satisfies a condition.
sort()Sorts the elements of the array.
splice()Changes the contents of an array by removing/replacing elements.
toLocaleString()Returns a localized string representation of the array.
toReversed()Returns a reversed copy of the array.
toSorted()Returns a sorted copy of the array.
toSpliced()Returns a spliced copy of the array.
toString()Returns a string representation of the array.
unshift()Adds one or more elements to the start of the array.
values()Returns an iterator with values of the array.
with()Creates a new array with a modified element at a specific index.

4 Instance Properties

PropertyDescription
lengthReturns the number of elements in the array.

This tutorial provides an overview of the Array class in JavaScript. Each method and property can be explored further by testing examples in your JavaScript environment or referring to the official MDN documentation.