Arrays Flashcards

1
Q

How is an array declared?

A

let arr = []

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

What method is used to append an element to the end of an array?

A

.push(value)

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

What method is used to remove an element from the end of an array?

A

.pop()

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

How do you return an element from a specific index?

A

arr.at(index)

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

How do you set an element at a specific index?

A

arr[index] = value;

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

How do you convert an array to a string of comma separated values?

A

array.toString()

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

How do you remove the first element from an array?

A

shift()
This method removes the first element from an array and returns that removed element. It changes the length of the array.

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

How do you add one or more elements to the beginning of an array?

A

unshift(…items) -
Adds one or more elements to the beginning of an array and returns the new length of the array.

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

How do you remove an element from an array at a specific index without changing the length of the array?

A

delete arr[index] - Removes an element at the specified index. This operation leaves a hole (undefined element) in the array and does not change the array’s length.

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

How do you merge two or more arrays into a new array?

A

arr.concat(…values) - Merges two or more arrays or values into a new array without modifying the original arrays.

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

How do you create a new array with all sub-array elements concatenated into it recursively up to a specified depth?

A

arr.flat(depth) - Creates a new array with all sub-array elements concatenated into it up to the specified depth. The default depth is 1.

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

How do you change the contents of an array by removing or replacing existing elements and/or adding new elements?

A

arr.splice(start, deleteCount, …items) - Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

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

How do you return a shallow copy of a portion of an array into a new array object in JavaScript?

A

let new_arr = arr.slice(start,end) - Returns a shallow copy of a portion of an array into a new array object. It selects from start to end (end not included). The original array is not modified.

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

How do you find the first index of a specified element in an array?

A

indexOf(searchElement, fromIndex) - Returns the first index at which a given element can be found in the array, or -1 if it is not present. The search starts from fromIndex if provided.

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

How do you find the last index of a specified element in an array?

A

lastIndexOf(searchElement, fromIndex) - Returns the last index at which a given element can be found in the array, or -1 if it is not present. The search starts backward from fromIndex.

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

How do you determine whether an array includes a certain value?

A

includes(searchElement, fromIndex) - Determines whether the array includes a certain value, returning true or false. The search starts from fromIndex if provided.

17
Q

How do you find the first element in an array that satisfies a provided testing function?

A

arr.find - Returns the value of the first element in the array that satisfies the provided testing function. Otherwise, it returns undefined.

18
Q

How do you find the index of the first element in an array that satisfies a provided testing function?

A

findIndex(testFunction, thisArg) - Returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1.

19
Q

How do you find the last element in an array that satisfies a provided testing function?

A

findLast(testFunction, thisArg) - Returns the value of the last element in the array that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned.

20
Q

How do you find the index of the last element in an array that satisfies a provided testing function?

A

findLastIndex(testFunction, thisArg) - Returns the index of the last element in the array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.