JS Arrays Flashcards

1
Q

array1.concat(array2, array3, …, arrayX)

A

Returns Array. Joins two or more arrays, and returns a copy of the joined arrays

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

array.copyWithin(target, ?start, ?end)

target: The index position to copy the elements to
start: The index position to start copying elements from (default is 0)
end: The index position to stop copying elements from (default is array.length)

A

Returns modified Array. Copies array elements within the array, to and from specified positions

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

array.every(function(currentValue, ?index, ?arr), ?thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns Boolean. Checks if every element in an array pass a test

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

array.fill(value, start, end)

A

Returns modified Array. Fill the elements in an array with a static value

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

array.filter(function(currentValue, index, arr), thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns new Array. Creates a new array with every element in an array that pass a test

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

array.find(function(currentValue, index, arr),thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns the value of the first element in an array that pass a test; returns undefined is none pass

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

array.findIndex(function(currentValue, index, arr), thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns the index of the first element in an array that pass a test; if none, returns -1

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

array.forEach(function(currentValue, index, arr), thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Calls a function for each array element

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

array.indexOf(item, ?start)

if start negative will count from end and continue to end

A

Search the array for an element and returns its position

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

Array.isArray(obj)

A

Return Boolean. Checks whether an object is an array

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

array.join(?separator)

if no separator, defaults to comma

A

Returns String. Joins all elements of an array into a string

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

array. lastIndexOf(item, ?start)
start: Where to start the search. Negative values will start at the given position counting from the end, and search to the beginning

A

Search the array for an element, starting at the end, and returns its position

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

array.map(function(currentValue, index, arr), thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns new Array. Creates a new array with the result of calling a function for each array element

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

array.pop()

A

Removes the last element of an array, and returns that element, changes original array

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

array.push(item1, item2, …, itemX)

A

Adds new elements to the end of an array, and returns the new length

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

array.reduce(function(total, currentValue, currentIndex, arr), ?initialValue)

Function arguments:
total: The initialValue, or the previously returned value of the function
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

initialValue: A value to be passed to the function as the initial value

A

Reduce the values of an array to a single value (going left-to-right), Returns the accumulated result from the last call of the callback function

17
Q

array.reduceRight(function(total, currentValue, currentIndex, arr), initialValue)

Function arguments:
total: The initialValue, or the previously returned value of the function
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

initialValue: A value to be passed to the function as the initial value

A

Reduce the values of an array to a single value (going right-to-left), Returns the accumulated result from the last call of the callback function

18
Q

array.reverse()

A

Returns modified array. Reverses the order of the elements in an array

19
Q

array.shift()

A

Removes the first element of an array, and returns that element, changes original array

20
Q

array. slice(?start, ?end)
start: An integer that specifies where to start the selection (The first element has an index of 0). Use negative numbers to select from the end of an array. If omitted, it acts like “0”
end: An integer that specifies where to end the selection. If omitted, all elements from the start position and to the end of the array will be selected. Use negative numbers to select from the end of an array

A

Selects a part of an array, and returns the new array

21
Q

array.some(function(currentValue, index, arr), thisValue)

Function arguments:
currentValue: The value of the current element
index: The array index of the current element
arr: The array object the current element belongs to

thisValue: A value to be passed to the function to be used as its “this” value.
If this parameter is empty, the value “undefined” will be passed as its “this” value

A

Returns Boolean. Checks if any of the elements in an array pass a test

22
Q

array.sort(?compareFunction)

Default sorts as strings alphabetically

compareFunction: A function that defines an alternative sort order. The function should return a negative, zero, or positive value, depending on the arguments, like:
function(a, b){return a-b}
When the sort() method compares two values, it sends the values to the compare function, and sorts the values according to the returned (negative, zero, positive) value.
Ex. var points = [40, 100, 1, 5, 25, 10];
points.sort(function(a, b){return a-b});
A

Returns modified array. Sorts the elements of an array

23
Q

array.splice(index, ?howmany, ?item1, ….., itemX)

index: An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array
howmany: The number of items to be removed. If set to 0, no items will be removed
item1, …, itemX: The new item(s) to be added to the array

Ex.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");
The result of fruits will be:
Banana,Orange,Lemon,Kiwi,Mango
A

Returns a new Array, containing the removed items (if any). Modifies original array. Adds/Removes elements from an array

24
Q

array.toString()

A

Converts an array to a string, and returns the result

25
Q

array.unshift(item1, item2, …, itemX)

A

Adds new elements to the beginning of an array, and returns the new length

26
Q

array.valueOf()

A

Returns the primitive value of an array