Arrays Flashcards

1
Q

Array.concat() ?

Parameters?

Returns?

A

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

parameters: as many values (arrays) as you want

new Array instance

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

Array.every() ?

Parameters?

Returns?

A

tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

parameters: callbackFn - element, index (optional), array (optional)

bool

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

Array.at(index)

A

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.

returns element || undefined

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

arr = [1,2,3,4];

arr.length = 1;

What is length doing?

A

Truncating the array to one element

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

Array.length does what?

A

Returns the number of elements in the array (1 indexed)

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

Array.filter() ?

Parameters?

Returns?

A

creates a new array with all elements that pass the test implemented by the provided function

parameters: callbackFn that accepts - an element, index (optional), array (optional)

new filtered Array instance

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

Array.find() ?

Parameters?

Returns?

A

returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned

parameters: callbackFn that accepts - an element, index (optional), array (optional)

element || undefined

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

Array.findIndex() ?

Parameters?

Returns?

A

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

parameters: callbackFn that accepts - an element, index (optional), array (optional)

index of the first element in the array that passes the test || -1.

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

Array.flat() ?

Parameters?

Returns?

A

creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

parameters: depth

new array with the sub-array elements concatenated into it

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

Array.flatMap() ?

Parameters?

Returns?

A

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.

parameter: callbackFn which takes a current element, index, the array

new array with each element being the result of the callback function and flattened to a depth of 1

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

Array.forEach() ?

Parameters?

Returns?

A

executes a provided function once for each array element

parameters: callbackFn(element,index, the array)
undefined. doesn’t return anything just runs the function on each element.

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

Array.from() ?

Parameters?

Returns?

A

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

parameters: An array-like or iterable object to convert to an array, (optional) map fn

new array instance

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

Array.includes() ?

Parameters?

Returns?

A

determines whether an array includes a certain value among its entries,

parameters: searchElement, (optional) fromIndex
* * method is case sensitive **

returns bool

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

Array.indexOf() ?

Parameters?

Returns?

A

returns the first index at which a given element can be found in the array

parameters: searchElement, (optional) fromIndex

returns first index of the element in the array or -1

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

Array.join() ?

Parameters?

Returns?

A

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

parameters: (optional) separator

returns A string with all array elements joined

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

Array.map() ?

Parameters?

Returns?

A

creates a new array populated with the results of calling a provided function on every element in the calling array

parameters: callbackFn(element, index, the array)

returns new array with each element being the result of the callback function

17
Q

Array.pop() ?

Parameters?

Returns?

A

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

parameters: none

returns the removed element from the array; undefined if the array is empty.

18
Q

Array.push() ?

Parameters?

Returns?

A

adds one or more elements to the end of an array and returns the new length of the array

parameters: element(s)

returns updated array with new elements on the end.

19
Q

Array.reduce()
Parameters?
Returns?

A

executes a user-supplied “reducer” callback function on each element of the array, in order, 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.

callback fn: prevValue, curValue, curIndex, array, initial value (optional)

returns The value that results from running the “reducer” callback function to completion over the entire array.

20
Q

Array.reverse()

Parameters ?

Returns ?

A

reverses an array in place. The first array element becomes the last, and the last array element becomes the first

params: none

returns the reversed array

21
Q

Array.shift()

Parameters?

Returns?

A

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

params: none

returns removed value || undefined if empty

22
Q

Array.slice()

Parameters ?

Returns ?

A

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.

params: start (optional, can be negative) , end (optional, not included in the slice)

returns new shallow copy of the extracted array

23
Q

Array.some()
Params?
Returns?

A

tests whether at least one element in the array passes the test. returns true if, it finds an element for which the provided function returns true; otherwise returns false. doesn’t modify the array.

callback fn: element, index, array

returns bool

24
Q

Array.sort()

Params?

Returns?

A

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.

params: compare fn w/ 2 args (a,b) (optional)

returns an in-place sorted array

25
Q

Array.splice()

Parameters?

Returns?

A

changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

params: start, deleteCount, item(s)

returns an array of deleted elements

26
Q

Array.toString()

Parameters?

Returns?

A

returns a string representing the specified array and its elements

params: none

returns string of array elements

27
Q

Array.unshift()

Parameters?

Returns?

A

adds one or more elements to the beginning of an array and returns the new length of the array.

params: as many elements as you want

returns the new length property of the object upon which the method was called.