The document provides an overview of JavaScript array functions, categorized into sections for creating and checking arrays, adding and removing elements, searching and testing, looping and transforming, sorting and combining, and other useful methods. Each function is described with its purpose, such as checking if a value is an array, adding/removing items, and transforming arrays. This serves as a reference for developers to utilize various array functionalities in JavaScript.
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 ratings0% found this document useful (0 votes)
3 views2 pages
JavaScript_Array_Functions
The document provides an overview of JavaScript array functions, categorized into sections for creating and checking arrays, adding and removing elements, searching and testing, looping and transforming, sorting and combining, and other useful methods. Each function is described with its purpose, such as checking if a value is an array, adding/removing items, and transforming arrays. This serves as a reference for developers to utilize various array functionalities in JavaScript.
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
You are on page 1/ 2
JavaScript Array Functions
Creating and Checking Arrays
Function Description Array.isArray(arr) Checks if the value is an array. Array.of(...items) Creates a new array with the given elements. Array.from(obj) Creates a new array from an iterable or array-like object.
Adding and Removing Elements
Function Description push(item) Adds one or more items to the end of the array. pop() Removes the last item from the array. unshift(item) Adds one or more items to the beginning of the array. shift() Removes the first item from the array. splice(start, deleteCount, ...items) Adds/removes elements at a specific index. slice(start, end) Returns a new array with a portion of the original.
Searching and Testing
Function Description includes(value) Checks if the array includes a value. indexOf(value) Returns the first index of the value (or -1). lastIndexOf(value) Returns the last index of the value (or -1). find(callback) Returns the first item that matches a condition. findIndex(callback) Returns the index of the first item that matches. some(callback) Returns true if any item matches the condition. every(callback) Returns true if all items match the condition.
Looping and Transforming
Function Description forEach(callback) Executes a function for each item. map(callback) Returns a new array after transforming each item. filter(callback) Returns a new array with only matching items. reduce(callback, initialValue) Reduces the array to a single value. reduceRight(callback, initialValue) Same as reduce but from right to left. flat(depth) Flattens nested arrays up to the specified depth. flatMap(callback) Maps and flattens results one level deep.
Sorting and Combining
Function Description sort(compareFn) Sorts the array (default is lexicographic). reverse() Reverses the array in-place. concat(array2) Combines two or more arrays. join(separator) Joins all elements into a string.
Other Useful Methods
Function Description fill(value, start, end) Fills elements with a static value. copyWithin(target, start, end) Copies part of array to another location. toString() Converts the array to a string. entries() Returns an iterator with key/value pairs. keys() Returns an iterator with the keys (indexes). values() Returns an iterator with the values.