Array Methods Flashcards

1
Q

.at()

A

The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

.concat()

A

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

.copyWithin

A

The copyWithin() method shallow copies part of an array to another location in the same array and returns it without modifying its length.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

.entries()

A

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

.every()

A

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

.fill()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

.filter()

A

The filter() method creates a new array with all elements that pass the test implemented by the provided function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

.find()

A

The find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

.findIndex()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

.flat()

A

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

.flatMap()

A

The flatMap() method returns a new array formed by applying a given callback function to each element of the array, and then flattening the result by one level. It is identical to a map() followed by a flat() of depth 1, but slightly more efficient than calling those two methods separately.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

.forEach()

A

The forEach() method executes a provided function once for each array element.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

.from()

A

The Array.from() static method creates a new, shallow-copied Array instance from an array-like or iterable object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

.includes()

A

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

.indexOf()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

.isArray()

A

The Array.isArray() method determines whether the passed value is an Array.

17
Q

.join()

A

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.

18
Q

.keys()

A

The keys() method returns a new Array Iterator object that contains the keys for each index in the array.

19
Q

.lastIndexOf()

A

The lastIndexOf() method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

20
Q

.map()

A

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

21
Q

Array.of()

A

The Array.of() method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.

The difference between Array.of() and the Array constructor is in the handling of integer arguments: Array.of(7) creates an array with a single element, 7, whereas Array(7) creates an empty array with a length property of 7 (Note: this implies an array of 7 empty slots, not slots with actual undefined values).

22
Q

.pop()

A

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

23
Q

.push()

A

The push() method adds one or more elements to the end of an array and returns the new length of the array.

24
Q

.reduce()

A

The reduce() method executes a user-supplied “reducer” callback function on each element of the array, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

Perhaps the easiest-to-understand case for reduce() is to return the sum of all the elements in an array.

The reducer walks through the array element-by-element, at each step adding the current array value to the result from the previous step (this result is the running sum of all the previous steps) — until there are no more elements to add.

25
Q

.reduceRight()

A

The reduceRight() method applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value.

26
Q

.reverse()

A

The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.

27
Q

.shift()

A

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

28
Q

.slice()

A

The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.

29
Q

.some()

A

The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns true if, in the array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn’t modify the array.

30
Q

.sort()

A

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.

The time and space complexity of the sort cannot be guaranteed as it depends on the implementation.

31
Q

.splice

A

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To access part of an array without modifying it, see slice().

32
Q

toLocaleString()

A

The toLocaleString() method returns a string representing the elements of the array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma “,”).

33
Q

toLocaleString()

A

The toLocaleString() method returns a string representing the elements of the array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma “,”).

34
Q

toString()

A

The toString() method returns a string representing the specified array and its elements.

35
Q

.unshift()

A

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

36
Q

.value()

A

The values() method returns a new array iterator object that contains the values for each index in the array.