JS Array Flashcards

1
Q

Array.concat(array)

A

Combines both arrays and returns a new array without changing existing

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

When do async tasks is it better to use a forEach method or a for loop?

A

The for loop is better. forEach() is synchronous.

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

forEach()

A

synchronous method that will be used on all elements in an array

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

every()

A

works on elements in an array until it returns a falsy value

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

some()

A

loops through the array until the callback returns a truthy value

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

filter()

A

creates a new array with the callback values that returned truthy

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

map()

A

creates a new array from the values returned by the callback

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

reduce()

reduceRight()

A

builds up a value by repeatedly using the callback

reduceRight is in descending order RTL

needs an accumulator ‘sum’ | ‘total’

const total = numbers.reduce((sum, value) => {
  return sum + value;
})
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

push() and pop()

A

used to add to the tail and remove elements from the tail of an array

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

How is performance for forEach() or reduce() versus a traditional for loop?

A

forEach() and reduce() are faster for small to medium datasets, for loop is faster for large datasets (500,000+)

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

.from()

A

creates and array from a string

Array.from(“string”)

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

.toString()

A

returns a string with the array values seperated by commas

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

shift() and unshift()

A

Shift dequeues and element from the head

unshift inserts an element at the head

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

.sort() and .reverse()

A

sorts and reverses an array

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

.slice()

A

returns selected elements of an array as a new array(inclusive, exclusive)

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

.splice()

A

adds or removes items from an array

Array.splice(index, quantityToRemove, insert1, insert2,…)

17
Q

includes()

A

returns true if an array contains the value

18
Q

length

A

returns the size of the array

19
Q

How can you instantiate an array of fixed size?

A

array = new Array(size);

20
Q

Array.from()

A

Creates a new Array instance from an array-like object or iterable object.

21
Q

Array.isArray()

A

Returns true if the argument is an array, or false otherwise.

22
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.

Array.of(7); // [7] 1 slot
Array(7); // array of 7 empty slots

23
Q

Array.at()

A

Returns the array item at the given index. Accepts negative integers, which count back from the last item.

24
Q

Array.prototype.find()

A

Returns the value of the first element in the array that satisfies the provided testing function, orundefinedif no appropriate element is found.

25
Array.prototype.findLast()
Returns the value of the last element in the array that satisfies the provided testing function, or undefined if no appropriate element is found.
26
Array.prototype.findIndex() | Array.prototype.findLastIndex()
Returns the index of the first element in the array that satisfies the provided testing function, or -1 if no appropriate element was found. Returns the index of the last element in the array that satisfies the provided testing function, or -1 if no appropriate element was found.
27
Array.fill()
Fills all the elements of an array from a start index to an end index with a static value.
28
Array.prototype.join()
Joins all elements of an array into a string.
29
Array.prototype.keys()
Returns a new array iterator that contains the keys for each index in the calling array.
30
Array.toLocaleString()
Returns a localized string representing the calling array and its elements. Overrides the Object.prototype.toLocaleString() method.
31
Array.prototype.indexOf() Array.prototype.lastIndexOf()
Returns the first (least) index at which a given element can be found in the calling array. Returns the last (greatest) index at which a given element can be found in the calling array, or -1 if none is found.
32
Array.prototype.values()
Returns a new array iterator object that contains the values for each index in the array.
33
Array.prototype.copyWithin()
Copies a sequence of array elements within an array.
34
Array.prototype.flat()
Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.
35
Array.prototype.flatMap()
Returns a new array formed by applying a given callback function to each element of the calling array, and then flattening the result by one level.