JS Array Flashcards

1
Q

What is an Array

https://www.w3schools.com/jsref/jsref_obj_array.asp

A

The Array object is used to store multiple values in a single variable.

Example: const cars = [“Saab”, “Volvo”, “BMW”];

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

Array at()

https://www.w3schools.com/jsref/jsref_array_at.asp

A

The at() method returns an indexed element from an array.

The at() method returns the same as [].

index indicates the position of the element within the array (starting from 1)

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

Array concat()

https://www.w3schools.com/jsref/jsref_concat_array.asp

A

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.

the ( + ) just works the same way

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

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

Array constructor

https://www.w3schools.com/jsref/jsref_constructor_array.asp

A

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

array.constructor

function Array() { [native code] }

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

copyWithin()

https://www.w3schools.com/jsref/jsref_copywithin.asp

A

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.

array.copyWithin(target, start, end)

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

Array entries()

https://www.w3schools.com/jsref/jsref_entries.asp

A

The entries() method returns an Array Iterator object with key/value pairs:
[0, “Banana”]
[1, “Orange”]
[2, “Apple”]
[3, “Mango”]
The entries() method does not change the original array.

array.entries()

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

Array every()

https://www.w3schools.com/jsref/jsref_every.asp

A

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

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

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

fill()

https://www.w3schools.com/jsref/jsref_fill.asp

A

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.

array.fill(value, start, end)

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

filter()

https://www.w3schools.com/jsref/jsref_filter.asp

A

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.

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

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

find()

https://www.w3schools.com/jsref/jsref_find.asp

A

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.

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

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

findIndex()

https://www.w3schools.com/jsref/jsref_findindex.asp

A

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.

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

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

flat()

https://www.w3schools.com/jsref/jsref_array_flat.asp

A

The flat() method concatenates sub-array elements.

array.flat(depth)

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

flatMap()

https://www.w3schools.com/jsref/jsref_array_flatmap.asp

A

The flatMap() method maps all array elements and creates a new flat array.

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

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

flatMap() does not change the original array.

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

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

forEach()

https://www.w3schools.com/jsref/jsref_foreach.asp

A

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

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

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

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

Array.from()

https://www.w3schools.com/jsref/jsref_from.asp

A

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.

Array.from(object, mapFunction, thisValue)

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

includes()

https://www.w3schools.com/jsref/jsref_includes_array.asp

A

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.

array.includes(element, start)

17
Q

indexOf()

https://www.w3schools.com/jsref/jsref_includes_array.asp

A

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).

array.indexOf(item, start)

18
Q

Array.isArray()

https://www.w3schools.com/jsref/jsref_isarray.asp

A

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

Array.isArray(obj)

19
Q

join()

https://www.w3schools.com/jsref/jsref_join.asp

A

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 (,).

array.join(separator)

20
Q

keys()

https://www.w3schools.com/jsref/jsref_keys.asp

A

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

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

array.keys()

21
Q

lastIndexOf()

https://www.w3schools.com/jsref/jsref_lastindexof_array.asp

A

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).

array.lastIndexOf(item, start)

22
Q

length of .length

https://www.w3schools.com/jsref/jsref_length_array.asp

A

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

array.length | array.length = number

23
Q

map()

https://www.w3schools.com/jsref/jsref_map.asp

A

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

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

map() does not change the original array.

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

24
Q

pop()

https://www.w3schools.com/jsref/jsref_pop.asp

A

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.

array.pop()

25
Q

prototype

https://www.w3schools.com/jsref/jsref_prototype_array.asp

A

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

prototype is a property available with all JavaScript objects.

Array.prototype.name = value

26
Q

push()

https://www.w3schools.com/jsref/jsref_push.asp

A

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.

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

27
Q

reduce()

https://www.w3schools.com/jsref/jsref_reduce.asp

A

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.

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

28
Q

reduceRight()

https://www.w3schools.com/jsref/jsref_reduceright.asp

A

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.

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

29
Q

reverse()

https://www.w3schools.com/jsref/jsref_reverse.asp

A

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

The reverse() method overwrites the original array.

array.reverse()

30
Q

shift()

https://www.w3schools.com/jsref/jsref_shift.asp

A

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

The shift() method changes the original array.

The shift() method returns the shifted element.

array.shift()

31
Q

slice()

https://www.w3schools.com/jsref/jsref_slice_array.asp

A

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.

array.slice(start, end)

32
Q

some()

https://www.w3schools.com/jsref/jsref_some.asp

A

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.

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

33
Q

sort()

https://www.w3schools.com/jsref/jsref_sort.asp

A

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.

array.sort(compareFunction)

34
Q

splice()

https://www.w3schools.com/jsref/jsref_splice.asp

A

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

The splice() method overwrites the original array.

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

35
Q

toString()

https://www.w3schools.com/jsref/jsref_tostring_array.asp

A

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

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

array.toString()

36
Q

unshift()

https://www.w3schools.com/jsref/jsref_unshift.asp

A

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

The unshift() method overwrites the original array.

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

37
Q

valueOf()

https://www.w3schools.com/jsref/jsref_valueof_array.asp

A

The valueOf() method returns the array itself.

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

fruits.valueOf() returns the same as fruits.

array.valueOf()