Array Flashcards

1
Q

.push()

A

Adds x amount of elements to end of array & returns new length
* Mutating Method

The new length property of the object

Array.prototype.push(elementN)

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

.pop()

A

Removes last element and returns that element
* Mutating method

The removed element from the array; undefined if the array is empty

Array.prototype.pop()

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

shift()

A

Removes the first element and returns that removed element
* Mutating method
* Often used inside a while loop

The removed element from the array; undefined if the array is empty

Array.prototype.shift()

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

.unshift()

A

Adds x number elements to the beginning & returns new length
* Inserted in chunk at the beginning

The new length property of the object

Array.prototype.unshift(elementN)

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

slice()

A

Returns a shallow copy of a portion into a new array object
* end is not extracted, start is
* Often used with bind() and call() to create a utility method that converts an array-like object into an array

New array containing the extracted elements

Array.prototype.slice(start, end)

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

splice()

A

Changes the contents of an array by removing or replacing existing elements
* Mutating method

An array containing the deleted elements

Array.prototype.splice(start, deleteCount, itemN)

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

.sort()

A

Sorts the array in place
* Elements are converted to strings
* Should have a compareFn that specifies the sort order

The reference to the original array, now sorted

Array.prototype.sort((a,b) => {/*...*/})

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

.reverse()

A

Reverses the array in place
* Mutating method
* Preserves empty slots

The reference to the original array, now reversed

Array.prototype.reverse()

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

.concat()

A

Merge two or morre arrays
* Non-mutating method
* Creates a new array, first populated by elements in the object called on, then each argument is concatenated

A new Array instance

Array.prototype.concat(valueN)

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

.indexOf()

A

Returns the first index at which a given element can be found
* Uses strict equality

The first index of the element in the array; -1 if not found

Array.prototype.indexOf(searchElement, fromIndex)

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

.join()

A

Coverts the elements to a string and joins them together with a specified separator.
* if separator omitted, elements seperated by ,
* if array null / undefined, converted into an empty string

String with all elements joined. If length 0, the empty string returned

Array.prototype.join(separator)

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

.map()

A

New array with elements resulting from the function that was called onto each element.
* ^ can be an arrow function
* Iterative method & copying method
*

New array with each element being the result of the callback function

Array.prototype.map(callbackFn)

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

.filter()

A

Filters out elements on called array that pass the test implemented by the function
* Iterative method & copying method (shallow copy)
* Needs to return truthy to keep element in array

Shallow Copy, filtered to elements that pass the implemented test

Array.prototype.filter(testFunction(/*...*/))

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