22
33## Adding/Removing elements
44
5- - push(...items) <br >
6- add elements to the end
5+ - ** push** (...items) <br >
6+ _ add ` items ` to the end _
77
88``` js
99const arr = [1 , 2 , 3 ];
1010arr .push (4 );
1111// arr = [1, 2, 3, 4]
1212```
1313
14- - pop() <br >
15- extracts an element from the end
14+ - ** pop** () <br >
15+ _ extracts an element from the end _
1616
1717``` js
1818const arr = [1 , 2 , 3 ];
1919arr .pop ();
2020// arr = [1, 2]
2121```
2222
23- - unshift(...items) <br >
24- add items to the beginning (bad for performance)
23+ - ** unshift** (...items) <br >
24+ _ add ` items ` to the beginning (bad for performance)_
2525
2626``` js
2727const arr = [1 , 2 , 3 ];
2828arr .unshift (0 );
2929// arr = [0, 1, 2, 3]
3030```
3131
32- - shift() <br >
33- extracts from the beginning
32+ - ** shift** () <br >
33+ _ extracts from the beginning _
3434
3535``` js
3636const arr = [1 , 2 , 3 ];
3737arr .shift ();
3838// arr = [2, 3]
3939```
4040
41- - concat(...items) <br >
42- returns a new array: copy of the current array + ` items `
41+ - ** concat** (...items) <br >
42+ _ returns a new array: copy of the current array + ` items ` _
4343
4444``` js
4545const arr = [1 , 2 , 3 ];
@@ -48,17 +48,17 @@ const newArr2 = newArr.concat([6, 7]);
4848// newArr2 = [1, 2, 3, 4, 5, 6, 7]
4949```
5050
51- - splice(pos, count, ...items) <br >
52- at index ` pos ` deletes ` count ` elements and inserts ` items `
51+ - ** splice** (pos, count, ...items) <br >
52+ _ at index ` pos ` deletes ` count ` elements and inserts ` items ` _
5353
5454``` js
5555const arr = [" a" , " *" , " *" , " d" ];
5656arr .splice (1 , 2 , " b" , " c" );
5757// arr = ['a', 'b', 'c', d']
5858```
5959
60- - slice(start, end) <br >
61- creates a new array, copies elements from index ` start ` till ` end ` (not inclusive) into it
60+ - ** slice** (start, end) <br >
61+ _ creates a new array, copies elements from index ` start ` till ` end ` (not inclusive) into it _
6262
6363``` js
6464const arr = [1 , 2 , 3 , 4 , 5 ];
@@ -68,25 +68,25 @@ const newArr = arr.slice(1, 4);
6868
6969## Search among elements
7070
71- - indexOf/ lastIndexOf(item, pos) <br >
72- look for ` item ` starting from index ` pos ` , return the index or -1 if not found. Method ` lastIndexOf() ` searches from right to left
71+ - ** indexOf / lastIndexOf** (item, pos) <br >
72+ _ look for ` item ` starting from index ` pos ` , return it's index or -1 if not found. Method ` lastIndexOf() ` searches from right to left _
7373
7474``` js
7575const arr = [10 , 20 , 20 , 30 ];
7676const first = arr .indexOf (20 ); // first = 1
7777const last = arr .lastIndexOf (20 ); // last = 2
7878```
7979
80- - includes(value) <br >
81- returns true if the array has value, else false
80+ - ** includes** (value) <br >
81+ _ returns true if the array has value, else false _
8282
8383``` js
8484const arr = [10 , 20 , 30 , 40 ];
8585const n = arr .includes (15 ); // false
8686```
8787
88- - find/ findIndex(func(item, index, arr)) <br >
89- ` func() ` is called for each element of the array. If the ` func() ` returns true, the search is interrupted and item is returned, else - undefined
88+ - ** find / findIndex** (func(item, index, arr)) <br >
89+ _ ` func() ` is called for each element of the array. If the ` func() ` returns true, the search is interrupted and item is returned, else - undefined _
9090
9191``` js
9292const arr = [1 , 13 , 23 , 43 , 56 , 71 , 97 ]
@@ -96,8 +96,8 @@ const evenNum = arr.find(item => {
9696// evenNum = 56
9797```
9898
99- - filter(func(item, index, arr)) <br >
100- the method is similar to ` find() ` , but ` filter() ` returns an array of all matching elements
99+ - ** filter** (func(item, index, arr)) <br >
100+ _ the method is similar to ` find() ` , but ` filter() ` returns an array of all matching elements _
101101
102102``` js
103103const arr = [1 , 2 , 3 , 4 , 5 , 6 , 7 ];
@@ -108,8 +108,8 @@ const evenArr = arr.filter((item) => {
108108
109109## Iteration of elements
110110
111- - forEach(func(item, index, array)) <br >
112- calls ` func() ` for every element in array, does not return anything
111+ - ** forEach** (func(item, index, array)) <br >
112+ _ calls ` func() ` for every element in array, does not return anything _
113113
114114``` js
115115const arr = [1 , 2 , 3 ];
@@ -123,8 +123,8 @@ arr.forEach((item, index, arr) => {
123123
124124## Transform the array
125125
126- - map(func(item, index, array)) <br >
127- calls the ` func() ` for each element of the array and returns the array of results
126+ - ** map** (func(item, index, array)) <br >
127+ _ calls the ` func() ` for each element of the array and returns the array of results _
128128
129129``` js
130130const arr = [1 , 2 , 3 , 4 , 5 ];
@@ -134,8 +134,8 @@ const newArr = arr.map((item) => {
134134// newArr = [10, 20, 30, 40, 50]
135135```
136136
137- - sort(func()) <br >
138- sorts the array changing it's element order, ` func() ` defining the sorting order (optional).
137+ - ** sort** (func()) <br >
138+ _ sorts the array changing it's element order, ` func() ` defining the sorting order (optional)._
139139
140140``` js
141141const arr = [25 , 7 , 13 31 ]
@@ -145,17 +145,17 @@ arr.sort((a, b) => {
145145// arr = [7, 13, 25, 31]
146146```
147147
148- - reverse() <br >
149- reverse the order of the elements of the current array
148+ - ** reverse** () <br >
149+ _ reverse the order of the elements of the current array _
150150
151151``` js
152152const arr = [1 , 2 , 3 , 4 , 5 ];
153153arr .reverse ();
154154// arr = [5, 4, 3, 2, 1]
155155```
156156
157- - join(separator)/ string.split(separator) <br >
158- convert an array to string / a string to array
157+ - ** join** (separator) / string.split(separator) <br >
158+ _ convert an array to string / a string to array _
159159
160160``` js
161161const str = " one, two, three, four" ;
@@ -165,8 +165,8 @@ const newStr = arr.join("-");
165165// newStr = "one-two-three-four"
166166```
167167
168- - reduce/ reduceRight(func(accumulator, current, index, array), initial) <br >
169- calculate a single value over the array by calling ` func() ` for each element and passing an intermediate result between the calls
168+ - ** reduce / reduceRight** (func(accumulator, current, index, array), initial) <br >
169+ _ calculate a single value over the array by calling ` func() ` for each element and passing an intermediate result between the calls _
170170
171171``` js
172172const arr = [1 , 2 , 3 , 4 , 5 ];
0 commit comments