Array Methods Flashcards

1
Q

Joins arrays and returns an array with the joined arrays

A

concat()

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

The concat() method concatenates (joins) two or more arrays.

The concat() method returns a new array, containing the joined arrays.

The concat() method does not change the existing arrays.

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

Returns the function that created the Array object’s prototype

A

constructor

array.constructor

The constructor property returns the function that created the Array prototype.

For JavaScript arrays the constructor property returns:

function Array() { [native code] }

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

Copies array elements within the array, to and from specified positions

A

copyWithin()

array.copyWithin(target, start, end)

The copyWithin() method copies array elements to another position in the array.

The copyWithin() method overwrites the existing values.

The copyWithin() method does not add items to the array.

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

Returns a key/value pair Array Iteration Object

A

entries()

array.entries()

The entries() method does not change the original array.

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

Checks if every element in an array pass a test

A

every()

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

The every() method executes a function for each array element.

The every() method returns true if the function returns true for all elements.

The every() method returns false if the function returns false for one element.

The every() method does not execute the function for empty elements.

The every() method does not change the original array

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

Fill the elements in an array with a static value

A

fill()

array.fill(value, start, end)

The fill() method fills specified elements in an array with a value.

The fill() method overwrites the original array.

Start and end position can be specified. If not, all elements will be filled.

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

Creates a new array with every element in an array that passes a test

A

filter()

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

The filter() method creates a new array filled with elements that pass a test provided by a function.

The filter() method does not execute the function for empty elements.

The filter() method does not change the original array.

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

Returns the value of the first element in an array that passes a test

A

find()

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

The find() method returns the value of the first element that passes a test.

The find() method executes a function for each array element.

The find() method returns undefined if no elements are found.

The find() method does not execute the function for empty elements.

The find() method does not change the original array.

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

Returns the index of the first element in an array that pass a test

A

findIndex()

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

The findIndex() method executes a function for each array element.

The findIndex() method returns the index (position) of the first element that passes a test.

The findIndex() method returns -1 if no match is found.

The findIndex() method does not execute the function for empty array elements.

The findIndex() method does not change the original array.

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

Calls a function for each array element

A

forEach()

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

The forEach() method calls a function for each element in an array.

The forEach() method is not executed for empty elements.

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

Creates an array from an object

A

from()

Array.from(object, mapFunction, thisValue)

The Array.from() method returns an array from any object with a length property.

The Array.from() method returns an array from any iterable object.

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

Check if an array contains the specified element

A

includes()

array.includes(element, start)

The includes() method returns true if an array contains a specified value.

The includes() method returns false if the value is not found.

The includes() method is case sensitive.

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

Searches the array for an element and returns its position

A

indexOf()

array.indexOf(item, start)

The indexOf() method returns the first index (position) of a specified value.

The indexOf() method returns -1 if the value is not found.

The indexOf() method starts at a specified index and searches from left to right.

By default the search starts at the first element and ends at the last.

Negative start values counts from the last element (but still searches from left to right).

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

Checks whether an object is an array

A

isArray()

Array.isArray(obj)

The isArray() method returns true if an object is an array, otherwise false.

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

Joins all elements of an array into a string

A

join()

array.join(separator)

The join() method returns an array as a string.

The join() method does not change the original array.

Any separator can be specified. The default is comma (,).

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

Returns a Array Iteration Object, containing the keys of the original array

A

keys()

array.keys()

The keys() method returns an Array Iterator object with the keys of an array.

The keys() method does not change the original array.

17
Q

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

A

lastIndexOf()

array.lastIndexOf(item, start)

The lastIndexOf() method returns the last index (position) of a specified value.

The lastIndexOf() method returns -1 if the value is not found.

The lastIndexOf() starts at a specified index and searches from right to left.

By defalt the search starts at the last element and ends at the first.

Negative start values counts from the last element (but still searches from right to left).

18
Q

Sets or returns the number of elements in an array

A

length

array. length
array. length = number

The length property sets or returns the number of elements in an array.

19
Q

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

A

map()

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

map() creates a new array from calling a function for every array element.

map() calls a function once for each element in an array.

map() does not execute the function for empty elements.

map() does not change the original array.

20
Q

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

A

pop()

array.pop()

The pop() method removes (pops) the last element of an array.

The pop() method changes the original array.

The pop() method returns the removed element.

21
Q

Allows you to add properties and methods to an Array object

A

prototype

Array.prototype.name = value

prototype allows you to add new properties and methods to arrays.

prototype is a property available with all JavaScript objects.

22
Q

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

A

push()

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

The push() method adds new items to the end of an array.

The push() method changes the length of the array.

The push() method returns the new length.

23
Q

Reduce the values of an array to a single value (going left-to-right)

A

reduce()

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

The reduce() method executes a reducer function for array element.

The reduce() method returns a single value: the function’s accumulated result.

The reduce() method does not execute the function for empty array elements.

The reduce() method does not change the original array.

24
Q

Reduce the values of an array to a single value (going right-to-left)

A

reduceRight()

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

The reduceRight() method executes a reducer function for each array element.

The reduceRight() method works from right to left.

The reduceRight() method returns a single value: the function’s accumulated result.

The reduceRight() method does not execute the function for empty elements.

25
Q

Reverses the order of the elements in an array

A

reverse()

array.reverse()

The reverse() method reverses the order of the elements in an array.

The reverse() method overwrites the original array.

26
Q

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

A

shift()

array.shift()

The shift() method removes the first item of an array.

The shift() method changes the original array.

The shift() method returns the shifted element.

27
Q

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

A

slice()

array.slice(start, end)

The slice() method returns selected elements in an array, as a new array.

The slice() method selects from a given start, up to a (not inclusive) given end.

The slice() method does not change the original array.

28
Q

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

A

some()

array.some(function(value, index, arr), this)

The some() method checks if any array elements pass a test (provided as a callback function).

The some() method executes the callback function once for each array element.

The some() method returns true (and stops) if the function returns true for one of the array elements.

The some() method returns false if the function returns false for all of the array elements.

The some() method does not execute the function for empty array elements.

The some() method does not change the original array.

29
Q

Sorts the elements of an array

A

sort()

array.sort(compareFunction)

The sort() sorts the elements of an array.

The sort() overwrites the original array.

The sort() sorts the elements as strings in alphabetical and ascending order.

30
Q

Adds/Removes elements from an array

A

splice()

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

The splice() method adds and/or removes array elements.

The splice() method overwrites the original array.

31
Q

Converts an array to a string, and returns the result

A

toString()

array.toString()

The toString() method returns a string with array values separated by commas.

The toString() method does not change the original array.

32
Q

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

A

unshift()

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

The unshift() method adds new elements to the beginning of an array.

The unshift() method overwrites the original array.

33
Q

Returns the primitive value of an array

A

valueOf()

array.valueOf()

The valueOf() method returns the array itself.

The valueOf() method does not change the original array.

fruits.valueOf() returns the same as fruits.