JS Array Flashcards

1
Q

JavaScript Array concat() Method?

A

The concat() method is used to join two or more arrays.

This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.

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

JavaScript Array copyWithin() Method?

A

The copyWithin() method copies array elements to another position in the array, overwriting the existing values.
This method will never add more items to the array.
ex:
var fruits = [“Banana”, “Orange”, “Apple”, “Mango”, “Kiwi”, “Papaya”];
fruits.copyWithin(2, 0, 2);
Result:
Banana,Orange,Banana,Orange,Kiwi,Papaya
copies the first to at the index of zero AFTER the copies and keeps the last two in tack

array.copyWithin(target, start, end)

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

JavaScript Array entries() Method?

A

The entries() method returns an Array Iterator object with key/value pairs.

For each item in the original array, the new iteration object will contain an array with the index as the key, and the item value as the value:

[0, “Banana”]
[1, “Orange”]
[2, “Apple”]
[3, “Mango”]

ex:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var f = fruits.entries();

for (x of f) {
document.getElementById(“demo”).innerHTML += x;
}

Result:
0,Banana
1,Orange
2,Apple
3,Mango
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JavaScript Array every() Method?

A

The every() method checks if all elements in an array pass a test (provided as a function).

The every() method executes the function once for each element present in the array:

If it finds an array element where the function returns a false value, every() returns false (and does not check the remaining values)
If no false occur, every() returns true
Note: every() does not execute the function for array elements without values.

Note: every() does not change the original array. Returns TRUE OR FALSE

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

JavaScript Array fill() Method?

A
The fill() method fills the specified elements in an array with a static value.
You can specify the position of where to start and end the filling. If not specified, all elements will be filled.
array.fill(value, start, end)
Example:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi", 2, 4);
Resutlt:
 ["Banana", "Orange", "Kiwi", "Kiwi"];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JavaScript Array filter() Method?

A

The filter() method creates an array filled with all array elements that pass a test (provided as a function).

Note: filter() does not execute the function for array elements without values.

Note: filter() does not change the original array.

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

JavaScript Array find() Method?

A

The find() method returns the value of the first element in an array that pass a test (provided as a function).

The find() method executes the function once for each element present in the array:

If it finds an array element where the function returns a true value, find() returns the value of that array element (and does not check the remaining values)
Otherwise it returns undefined

Note: find() does not execute the function for empty arrays.

Note: find() does not change the original array.

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

JavaScript Array findIndex() Method?

A

The findIndex() method returns the index of the first element in an array that pass a test (provided as a function).

The findIndex() method executes the function once for each element present in the array:

If it finds an array element where the function returns a true value, findIndex() returns the index of that array element (and does not check the remaining values)
Otherwise it returns -1
Note: findIndex() does not execute the function for array elements without values.

Note: findIndex() does not change the original array.

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

JavaScript Array forEach() Method?

A

array.forEach(function(currentValue, index, arr), thisValue)
currentValue Required. The value of the current element
index: Optional. The array index of the current element
arr Optional. The array object the current element belongs to

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

JavaScript Array includes() Method

A

The includes() method determines whether an array contains a specified element.

This method returns true if the array contains the element, and false if not.

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

JavaScript Array indexOf() Method?

A

The indexOf() method searches the array for the specified item, and returns its position.

The search will start at the specified position, or at the beginning if no start position is specified, and end the search at the end of the array.

Returns -1 if the item is not found.

If the item is present more than once, the indexOf method returns the position of the first occurence.

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

JavaScript Array isArray() Method?

A

The isArray() method determines whether an object is an array.

This function returns true if the object is an array, and false if not.

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

JavaScript Array join() Method?

A

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

The elements will be separated by a specified separator. The default separator is comma (,).

Note: this method will not change the original array

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

JavaScript Array length Property?

A

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

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

JavaScript Array lastIndexOf() Method?

A
Definition and Usage
The lastIndexOf() method searches the array for the specified item, and returns its position.

The search will start at the specified position, or at the end if no start position is specified, and end the search at the beginning of the array.

Returns -1 if the item is not found.

If the item to search for is present more than once, the lastIndexOf method returns the position of the last occurence.

Syntax
array.lastIndexOf(item, start)

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

JavaScript Array map() Method?*

A
Definition and Usage
The map() method creates a new array with the results of calling a function for every array element.

The map() method calls the provided function once for each element in an array, in order.

Note: map() does not execute the function for array elements without values.

Note: this method does not change the original array.

17
Q

JavaScript Array pop() Method?

A

The pop() method removes the last element of an array, and returns that element.

Note: This method changes the length of an array.

18
Q

JavaScript Array push() Method?

A

The push() method adds new items to the end of an array, and returns the new length.

Note: The new item(s) will be added at the end of the array.

Note: This method changes the length of the array.

19
Q

JavaScript Array reduce() Method?*

A

The reduce() method reduces the array to a single value.

The reduce() method executes a provided function for each value of the array (from left-to-right).

The return value of the function is stored in an accumulator (result/total).

20
Q

JavaScript Array reduceRight() Method?

A

The reduceRight() method reduces the array to a single value.

The reduceRight() method executes a provided function for each value of the array (from right-to-left).

The return value of the function is stored in an accumulator (result/total).

Note: reduceRight() does not execute the function for array elements without values.

21
Q

JavaScript Array reverse() Method?

A

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

Note: this method will change the original array.

22
Q

JavaScript Array shift() Method?

A

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

Note: This method changes the length of the array.

Note: The return value of the shift method is the removed item.

Tip: To remove the last item of an array, use the pop() method.

Note: this method will change the original array.

23
Q

JavaScript Array slice() Method?

A
Definition and Usage
The slice() method returns the selected elements in an array, as a new array object.
The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument.
https://www.w3schools.com/jsref/jsref_slice_array.asp
24
Q

JavaScript Array some() Method?

A

The some() method checks if any of the elements in an array pass a test (provided as a function).

The some() method executes the function once for each element present in the array:

If it finds an array element where the function returns a true value, some() returns true (and does not check the remaining values)
Otherwise it returns false
Note: some() does not execute the function for array elements without values.

Note: some() does not change the original array.

25
Q

JavaScript Array sort() Method?*

A

The sort() method sorts the items of an array.

The sort order can be either alphabetic or numeric, and either ascending (up) or descending (down).

By default, the sort() method sorts the values as strings in alphabetical and ascending order.

This works well for strings (“Apple” comes before “Banana”). However, if numbers are sorted as strings, “25” is bigger than “100”, because “2” is bigger than “1”.

Because of this, the sort() method will produce an incorrect result when sorting numbers.

You can fix this by providing a “compare function” (See “Parameter Values” below).

26
Q

JavaScript Array splice() Method?

A

he splice() method adds/removes items to/from an array, and returns the removed item(s).

Note: This method changes the original array.
array.splice(index, howmany, item1, ….., itemX)

27
Q

JavaScript Array toString() Method?

A

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

28
Q

JavaScript Array unshift() Method?

A

The unshift() method adds new items to the beginning of an array, and returns the new length.

Note: This method changes the length of an array.

29
Q

JavaScript Array valueOf() Method?

A

The valueOf() method returns the array.

This method is the default method of the array object. Array.valueOf() will return the same as Array