Array Flashcards

1
Q

Array.from()

A

create an array from an array-like

params: arrayLike[, mapFn[, thisArg]]

arrayLike
An array-like or iterable object to convert to an array.
mapFn
Optional. Map function to call on every element of the array.
thisArg
Optional. Value to use as this when executing mapFn.

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

Array.isArray()

A

Determine if the passed in object is an array

params: obj

Note: necessary because an array from a different window might have an augmented Array.prototype, in which case instanceof might not work across the different windows.

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

Array.observe()

A

Asynchronously observe changes

params: arr, callback

arr
The array to observe
callback
The callback. Takes an array of change objects. Change objects have [propertyName, changedArray, typeOfChange, oldValue (for update and delete types), index + removed + addedCount (for splice type)]

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

Array.of()

A

Creates a new array from a list of args

params: element0[, …elementN]

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

Array.prototype.concat()

A

Returns combined arrays

params: arr1[, …arrN]

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

Array.prototype.copyWithin()

A

(Mutable) Copies part of an array to another part

params: target, start[, end]

target
    the index to start inserting
start
    the start of the copy range
end
    the end of the copy range, exclusive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Array.prototype.entries()

A

Returns a new Array Iterator. Each iteration returns an array [k, v]

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

Array.prototype.every()

A

Tests whether all elements pass a test

params: callback[, thisArg]

callback
args are [currentValue, index, arr]. return T/F
thisArg
the this binding for the callback

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

Array.prototype.fill()

A

fill an array with a value

params: value[, start[, end]]

value
    value to use
start
    start index
end
    end index, exclusive
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Array.prototype.filter()

A

Return a new array with only elements that pass the test

params: callback[, thisArg]

callback
args [elem, index, arr]. returns T/F
thisArg
the this binding for the callback

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

Array.prototype.find()

A

Returns a value from the array if an element satisfies the test

params: callback[, thisArg]

callback
Test (element, index, array)
thisArg
this binding

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

Array.prototype.findIndex()

A

Returns the first index of an element that satisfies the test

params: callback[, thisArg]

callback
Test (element, index, array)
thisArg
this binding

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

Array.prototype.forEach()

A

Executes a callback on each element of an array

params: callback[, thisArg]

callback
function (currentValue, index, arr)
thisArg
this binding

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

Array.prototype.includes()

A

Returns true if the array includes a value

params: searchElement[, fromIndex]

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

Array.prototype.indexOf()

A

Returns first index of an element

params: searchElement[, fromIndex=0]

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

Array.prototype.join()

A

joins all elements into a string

params: [separator = ‘,’]

Note: separator is converted to string

17
Q

Array.prototype.keys()

A

Returns an array iterator with keys for each index

Note: does not ignore holes like Object.keys() does

18
Q

Array.prototype.lastIndexOf()

A

Returns last index of fiven element

params: searchElement[, fromIndex = arr.length-1]

19
Q

Array.prototype.map()

A

Creates a new array with results of calling function on each element in array

params: callback[, thisArg]

callback
(currentValue, index, array)

20
Q

Array.prototype.pop()

A

Removes & returns last element

Note: intentionally generic, so you can call/apply it on objects resembling arrays

21
Q

Array.prototype.push()

A

Adds one or more elements. Returns new length

params: element1, …, elementN

Note: intentionally generic, so you can call/apply on objects resembling arrays

22
Q

Array.prototype.reduce()

A

Reduces an array to a single value

params: callback[, initialValue]

callback
(prevVal, currentVal, index, arr)
initialValue
first prevVal

23
Q

Array.prototype.reduceRight()

A

reduce from the right

24
Q

Array.prototype.reverse()

A

Reverse an array in place

25
Q

Array.prototype.shift()

A

Remove and return first element

Note: intentionally generic

26
Q

Array.prototype.slice()

A

Returns a shallow copy of part of the array

params: begin[, end]

begin
if negative, offset is from end. (-2) returns last two
end
exclusive. if negative, offset is from end

27
Q

Array.prototype.some()

A

Test whether at least one element passes a test

params: callback[, thisArg]

callback
(value, i, arr)
thisArg
this binding

28
Q

Array.prototype.sort()

A

Sorts an array in place

params: [compareFunction]

compareFunction
(a,b)

Note: numbers are converted to strings

29
Q

Array.prototype.splice()

A

Changes an array by adding/removing elements. Returns removed elements

params: start[, deleteCount[, item1[, itemN]]]

start
    if negative, will begin that many elements from end
deleteCount
    number of elements to delete
itemN
    elements to add
30
Q

Array.prototype.toLocaleString()

A

Returns a string representing elements in the array in locale-specific format

31
Q

Array.prototype.toString

A

outputs comma separated elements

32
Q

Array.prototype.unshift()

A

Adds elements to the beginning of a string

params: item1[, itemN]

Note: intentionally generic

33
Q

Array.prototype.values()

A

Returns an iterator with the values

34
Q

Array.unobserve

A

Remove observers set by observe

params: arr, callback

arr
the array to stop observing
callback
The reference to the observer that should not be called anymore