Methods Flashcards

1
Q

.forEach()

A
  • Used to iterate over each element in an array and perform a specified action
  • It executes a provided callback function once for each element in the array, in ascending order
  • Does not return a new array

var numbers = [1, 2, 3, 4, 5];
numbers.forEach(function(number) {
console.log(number);
});

Output:
1
2
3
4
5

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

.map()

A
  • Used to iterate over each element in an array, apply a transformation or operation to each element
  • Return a new array containing the results of that transformation.
  • It executes a provided callback function once for each element in the array and creates a new array based on the return values of the callback function.

var numbers = [1, 2, 3, 4, 5];
var multipliedNumbers = numbers.map(function(number) {
return number * 2;
});
console.log(multipliedNumbers);

Output:
[2, 4, 6, 8, 10]

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

.push()

A
  • Adds one or more elements to the end 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
4
Q

.pop()

A

Removes the last element from an array and returns that element.

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

.shift()

A

Removes the first element from an array and returns that element. It also shifts all subsequent elements to a lower index.

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

.unshift()

A

Adds one or more elements to the beginning of an array and returns the new length of the array. It also unshifts existing elements to a higher index.

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

.slice()

A

Returns a shallow copy of a portion of an array into a new array. It takes two arguments: the starting index (inclusive) and the ending index (exclusive).

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

.join()

A

Joins all elements of an array into a string using a specified separator and returns the resulting string.

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

.concat()

A

Combines (or concatinates) two or more arrays and returns a new array.

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

.filter()

A

Creates a new array with all elements that pass a provided test.

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

.split()

A

Splits a string into an array of substrings based on a specified separator.

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

.trim()

A

Removes whitespace from both ends of a string.

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

.includes()

A

Checks if a string contains a specified substring and returns true or false.

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

.charAt()

A

Returns the character at a specified index in a string.

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