Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8e0973a

Browse files
i added some array methods info to my cheatsheet
1 parent ab65e09 commit 8e0973a

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

‎CheatSheet for Array methods JS.txt

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,58 @@ What it returns: The filter() method returns a new array with the elements that
7777
Please note that the arrow function syntax can also be used instead of traditional function syntax in the example.
7878

7979

80+
81+
------------------------------------------------------------------------------------------------------------------------------------------
82+
83+
84+
Method Name: reduce()
85+
86+
Example: Calculate the sum of all numbers in an array.
87+
88+
const numbers = [1, 2, 3, 4, 5];
89+
90+
const sum = numbers.reduce(function(accumulator, currentValue) {
91+
return accumulator + currentValue;
92+
}, 0);
93+
94+
console.log(sum);
95+
96+
Does it mutate the source or not: The reduce() method does not mutate the source array. It performs calculations on the elements of the array and returns a single value.
97+
98+
Argument List and Meaning:
99+
100+
callback (required): The function to execute on each element. It takes four arguments:
101+
102+
accumulator: The accumulated value computed by previous iterations or the initial value provided.
103+
currentValue: The current element being processed in the array.
104+
index (optional): The index of the current element being processed.
105+
array (optional): The array that reduce() is being applied to.
106+
initialValue (optional): The initial value for the accumulator. If not provided, the first element of the array is used as the initial value.
107+
What it returns: The reduce() method returns a single value that results from the accumulation of values computed by the callback function.
108+
109+
110+
------------------------------------------------------------------------------------------------------------------------------------------
111+
112+
113+
Method Name: slice()
114+
115+
Example: Extract a portion of an array.
116+
117+
const fruits = ['apple', 'banana', 'orange', 'grape', 'mango'];
118+
119+
const slicedFruits = fruits.slice(1, 4);
120+
121+
console.log(slicedFruits);
122+
123+
Does it mutate the source or not: The slice() method does not mutate the source array. It returns a new array containing the extracted portion of the original array.
124+
125+
Argument List and Meaning:
126+
127+
start (optional): The index at which to begin extraction. If not specified, slice() starts from index 0.
128+
end (optional): The index at which to end extraction. The extracted portion does not include the element at the end index. If not specified, slice() extracts all elements from the start index to the end of the array.
129+
What it returns: The slice() method returns a new array containing the extracted portion of the original array.
130+
131+
Note: The original array is not modified. If either start or end is negative, it is treated as counting from the end of the array.
132+
133+
134+
------------------------------------------------------------------------------------------------------------------------------------------

‎interview.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
// isArray()
5151
// splice()
5252

53-
const num = [1,2,3,4,5,6,7];
54-
const str = 'Rim skdfokfokefe'
55-
console.log(num.at(0));
56-
console.log(str.at(0));
53+
// const num = [1,2,3,4,5,6,7];
54+
// const str = 'Rim skdfokfokefe'
55+
// console.log(num.at(0));
56+
// console.log(str.at(0));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /