Skip to content

Latest commit

 

History

History
96 lines (81 loc) · 24.9 KB

File metadata and controls

96 lines (81 loc) · 24.9 KB

Array

JavaScript New Array Methods for Better and Cleaner Code 4/4/25
JavaScript New Array Methods for Better and Cleaner Code 3/15/25
Array.reduce() is Goated 🐐✨ 5/14/24
The new Array.prototype.toSpliced() method in vanilla JS 9/12/23
How to deep merge arrays and objects with JavaScript 4/27/23
One Array Method to Rule Them All: Demystifying JavaScript’s reduce() 6/11/23

2021

How to remove duplicates from an array with vanilla JS 4/1
The Array.from() method in vanilla JS also lets you update values 3/9
The Array.shift() method in vanilla JS 3/2
How to get the index of an array item in a vanilla JS for...of loop 2/11
The Array.isArray() method in vanilla JS 1/16

2020

Passing Arrays as Function Arguments 10/12
Checking if a value is an array with vanilla JS 9/2
How to find specific items in an array with vanilla JS 9/1
Removing duplicates from an array with the vanilla JS Set() object 8/1
How to reorder an item in an array with vanilla JS 7/16
JavaScript: How to Remove Duplicate Values from Arrays 7/5
How I work with arrays 6/17
Revisiting Array.reduce() 6/9
When to use which array method in vanilla JS 6/3
Getting the last matching item in an array with vanilla JS 4/20
How to flatten an array with vanilla JS 4/7
Five interesting ways (and one boring way) to use Array.reduce() 12/19/2019
13 useful Array tips and tricks
MDN Array
//array literal
const names = [];

const names = new Array(); //longer way to create an array

//first items in arrays start at 0
.from() The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.
.isArray()
.of() The Array.of() method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.

Methods

.every() The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
.flat() The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
.find() The find() method returns the value of the first element in the provided array that satisfies the provided testing function.
.findIndex() The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.
.fill() The fill() method changes all elements in an array to a static value, from a start index (default 0) to an end index (default array.length). It returns the modified array.
.filter() The filter() method creates a new array with all elements that pass the test implemented by the provided function.
.forEach() The forEach() method executes a provided function once for each array element.
.from() The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.
.includes() The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
.indexOf() The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
.join() The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
.keys() The keys() method returns a new Array Iterator object that contains the keys for each index in the array.
.lastIndexOf() The lastIndexOf() method returns the index within the calling String object of the last occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the value is not found.
.length The length property of an object which is an instance of type Array sets or returns the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.
.map() The map() method creates a new array with the results of calling a provided function on every element in the calling array.
.pop() The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
.push() The push() method adds one or more elements to the end of an array and returns the new length of the array.
.reduce() The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.
.reverse() The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.
.shift() The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.
.slice() The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included) where begin and end represent the index of items in that array. The original array will not be modified.
.slice.call()
.some() The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.
.sort() The sort() method sorts the elements of an array in place and returns the sorted array. The default sort order is ascending, built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
.splice() The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
.split() The split() method turns a String into an array of strings, by separating the string at each instance of a specified separator string.
.unshift() The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

Objects

.entries() The Object.entries() method returns an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for...in loop. (The only important difference is that a for...in loop enumerates properties in the prototype chain as well).
.keys()
.values()