Array and object methods, iteration, and manipulation in JavaScript.
41 cards · basic cards · AI-written, checked twice. Edit anything.
- What does Array.push() do?
- Adds one or more elements to the end of an array and returns the new length. Mutates the original array.
- What does Array.pop() do?
- Removes the last element from an array and returns that element. Mutates the original array. Returns undefined if array is empty.
- What does Array.shift() do?
- Removes the first element from an array and returns that element. Mutates the original array. Returns undefined if array is empty.
- What does Array.unshift() do?
- Adds one or more elements to the beginning of an array and returns the new length. Mutates the original array.
- What does Array.slice() do?
- Returns a shallow copy of a portion of an array. Does not mutate the original array. Takes start and end indices.
- What does Array.splice() do?
- Removes elements from an array and optionally inserts new elements. Mutates the original array and returns an array of removed elements.
- What does Array.concat() do?
- Combines two or more arrays into a new array. Returns a new array and does not mutate the originals.
- What does Array.join() do?
- Combines all array elements into a single string, separated by a specified separator. Default separator is comma.
- What does Array.indexOf() do?
- Returns the index of the first element that matches the search value. Returns -1 if not found.
- What does Array.includes() do?
- Checks whether an array contains a specified element and returns a boolean. More readable than indexOf for simple presence checks.
- What does Array.reverse() do?
- Reverses the order of elements in an array in place. Mutates the original array and returns a reference to it.
- What does Array.sort() do?
- Sorts elements in an array in place. By default sorts lexicographically as strings. Takes optional comparison function.
- What does Array.map() do?
- Transforms each element in an array using a callback function and returns a new array. Does not mutate the original array.
- What does Array.filter() do?
- Creates a new array with elements that pass the test in the callback function. Does not mutate the original array.
- What does Array.reduce() do?
- Accumulates array elements into a single value by applying a callback function. Takes a callback and optional initial value.