Skip to content

Commit 2bea1a5

Browse files
authored
Update 28-Array.md
1 parent 623e8c0 commit 2bea1a5

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

notes/English/28-Array.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
### What is an Array in JavaScript?
1+
### What is an Array ?
22
An array in JavaScript is a data structure that stores a collection of elements, such as numbers or strings, in a linear fashion. Each element in an array is assigned a unique index starting from 0, which can be used to access and modify its value. Arrays in JavaScript can dynamically grow or shrink in size and support various methods for manipulating their contents.
33

44

5-
### Need of Array in JavaScript?
5+
### Need of Array ?
66
Arrays are an essential data structure in JavaScript as they allow you to store and manipulate collections of data, such as lists of numbers or strings. They provide a way to access elements using index positions, add or remove elements, sort the array, and perform various operations on the data efficiently. Arrays are also useful for organizing and structuring code, and many programming tasks involve working with arrays in some form.
77

88

9-
### How to create an Array in JavaScript?
9+
### How to create an Array ?
1010
You can create an array in JavaScript by using square brackets []. Here's an example code snippet:
1111

1212
```
@@ -20,15 +20,15 @@ let anotherArray = [1, 2, 3, "hello", true];
2020
In the example above, `myArray` is an empty array and `anotherArray` is an array that contains five elements of different data types. Note that arrays in JavaScript are dynamic, which means you can add or remove elements from them at any time.
2121

2222

23-
### Array Literal in JavaScript?
23+
### Array Literal ?
2424
An array literal in JavaScript is a way to create an array by enclosing a comma-separated list of values inside square brackets, like this: `[value1, value2, value3]`. For example, `let myArray = [1, 2, 3];` creates an array named `myArray` with three elements containing the values 1, 2, and 3. Array literals are a convenient way to initialize arrays with known values.
2525

2626

27-
### Array Object in JavaScript?
27+
### Array Object ?
2828
In JavaScript, an array is an object that stores a collection of values in a list-like structure. It can hold any type of data, including numbers, strings, objects, and even other arrays. The elements in an array are identified by their index, which starts at 0 for the first element and increments by 1 for each subsequent element. You can create an array using the array literal notation, or by using the Array constructor function. Arrays have many built-in methods for manipulating and iterating over their elements, such as push(), pop(), slice(), forEach(), map(), and reduce().
2929

3030

31-
### Index of Array in JavaScript?
31+
### Index of Array ?
3232
In JavaScript, the index of an array is a numerical value used to access and manipulate its elements. The first element in an array has an index of 0, the second element has an index of 1, and so on. You can access an element in an array using its index by placing the index within square brackets after the name of the array. For example:
3333

3434
```
@@ -39,11 +39,11 @@ console.log(myArray[2]); // Output: "orange"
3939
```
4040

4141

42-
### Array length property in JavaScript?
42+
### Array length property ?
4343
In JavaScript, the length property of an array returns the number of elements in the array. For example, if an array has three elements, its length property will return 3. The length property is automatically updated when elements are added to or removed from the array.
4444

4545

46-
### Array Declaration in JavaScript?
46+
### Array Declaration ?
4747
In JavaScript, an array can be declared using square brackets with comma-separated values inside the brackets or by calling the Array constructor.
4848

4949
For example:
@@ -63,7 +63,7 @@ const myArray = new Array(1, 2, 3, 4, 5);
6363
Note that in both cases, the values inside the array can be of any data type (such as numbers, strings, objects, etc.). Additionally, arrays in JavaScript are dynamic and can grow or shrink as needed.
6464

6565

66-
### Looping Array in JavaScript?
66+
### Looping Array ?
6767
To loop through an array in JavaScript, you can use a `for` loop or the `forEach()` method.
6868

6969
Using a `for` loop:
@@ -107,7 +107,7 @@ This uses a compare function that subtracts `b` from `a` instead of subtracting
107107
Note that the `sort()` function modifies the original array and returns the sorted array.
108108

109109

110-
### push function in JavaScript?
110+
### push function ?
111111
The "push()" function is a built-in method in JavaScript arrays that adds one or more elements to the end of an array and returns the new length of the array. The syntax for using the push() function is:
112112

113113
```javascript
@@ -117,7 +117,7 @@ array.push(element1, element2, ..., elementN)
117117
where "array" is the name of the array, and "element1", "element2", ..., "elementN" are the elements to be added to the end of the array.
118118

119119

120-
### pop function in JavaScript?
120+
### pop function ?
121121
In JavaScript, the `pop()` function can be used on an array to remove and return the last element of the array. The array's length is reduced by 1 after calling this function. Here's an example:
122122

123123
```
@@ -128,7 +128,7 @@ console.log(fruits); // output: ['apple', 'banana']
128128
```
129129

130130

131-
### unshift function in JavaScript?
131+
### unshift function ?
132132
The unshift() function in JavaScript is an array method that adds one or more elements to the beginning of an array and returns the new length of the array. The original array is modified by adding the elements at the beginning. The syntax is as follows:
133133

134134
```
@@ -138,7 +138,7 @@ array.unshift(element1, element2, ..., elementN)
138138
where `element1`, `element2`, ..., `elementN` are the elements to be added to the beginning of the array.
139139

140140

141-
### shift function in JavaScript?
141+
### shift function ?
142142
In JavaScript, the shift() function is used to remove the first element from an array and return it. This function also updates the length and indexes of the remaining elements in the array.
143143

144144
Example:
@@ -150,11 +150,11 @@ console.log(fruits); // output: ['banana', 'orange']
150150
```
151151

152152

153-
### toString function in JavaScript?
153+
### toString function ?
154154
In JavaScript, the `toString` function is a method that can be called on an object to convert it into a string representation. By default, the `toString` method returns a string representing the object. However, some built-in objects like `Date`, `Array`, and `RegExp` override this method to provide a more meaningful string representation of the object. Additionally, developers can also override the `toString` method for their own custom objects to provide a customized string representation.
155155

156156

157-
### join function in JavaScript?
157+
### join function ?
158158
The `join()` function is a built-in method in JavaScript that converts an array into a string by concatenating all elements of the array with a specified separator. The syntax for using `join()` is as follows:
159159

160160
```
@@ -182,7 +182,7 @@ const myString = myArray.join('-'); // "apple-banana-cherry"
182182
```
183183

184184

185-
### concat function in JavaScript?
185+
### concat function ?
186186
In JavaScript, the `concat()` function is used to merge two or more arrays together and create a new array that contains all the elements from the original arrays. The syntax for `concat()` is as follows:
187187

188188
```
@@ -192,7 +192,7 @@ newArray = array1.concat(array2, array3, ..., arrayN);
192192
where `array1` is the initial array, and `array2`, `array3`, ..., `arrayN` are additional arrays that will be concatenated onto `array1`. The resulting `newArray` will contain all the elements from each of the input arrays in the order they were passed into the function.
193193

194194

195-
### splice function in JavaScript?
195+
### splice function ?
196196
The `splice()` function in JavaScript is used to add or remove elements from an array at a specified index. It has the following syntax:
197197

198198
```
@@ -206,11 +206,11 @@ array.splice(startIndex, deleteCount, element1, ..., elementN);
206206
The `splice()` function returns an array containing the deleted elements, or an empty array if no elements were deleted. If elements were added to the array, the original array is modified and returned.
207207

208208

209-
### slice function in JavaScript?
209+
### slice function ?
210210
The slice() function in JavaScript creates a new array by copying a portion of an existing array. It takes two arguments: the starting index (inclusive) and the ending index (exclusive) of the portion to be copied. If no ending index is provided, the slice includes all elements from the starting index to the end of the array. The original array is not modified by the slice function.
211211

212212

213-
### sort function in JavaScript?
213+
### sort function ?
214214
The `sort()` function in JavaScript is a built-in method that allows you to sort the elements of an array in place, meaning it modifies the original array. You can call the `sort()` function on an array and pass in a compare function as its argument to specify how the elements should be sorted. If no compare function is passed in, the elements are sorted alphabetically by default.
215215

216216
Example usage:
@@ -226,7 +226,7 @@ numbers.sort(descending); // sorts numerically in descending order: [9, 6, 5, 5,
226226
```
227227

228228

229-
### reverse function in JavaScript?
229+
### reverse function ?
230230
In JavaScript, you can reverse a string or an array using the `reverse()` method.
231231

232232
For example, to reverse a string:
@@ -246,21 +246,21 @@ console.log(reversedArr); // Output: [4, 3, 2, 1]
246246
```
247247

248248

249-
### forEach function in JavaScript?
249+
### forEach function ?
250250
The forEach function is a built-in method in JavaScript that is used to iterate over an array or array-like object and execute a callback function for each element. The callback function is passed three arguments: the current element, its index, and the entire array being iterated. The forEach function does not return anything, it simply executes the provided function on each element of the array.
251251

252252

253-
### at function in JavaScript?
253+
### at function ?
254254
The `at` function in JavaScript is used to retrieve an element from an array at a specific index. It takes one parameter, which is the index of the element to be retrieved. The index can be a positive or negative integer, where negative indices are counted from the end of the array. The function returns the element if it exists at the specified index, and undefined otherwise.
255255

256256
Note that the `at` function is relatively new and may not be supported by all browsers. In older browsers or environments without support for `at`, you can use bracket notation (e.g., `myArray[index]`) instead to access array elements.
257257

258258

259-
### map function in JavaScript?
259+
### map function ?
260260
The `map()` function in JavaScript is a built-in method available in Array objects. It creates a new array by calling a provided function on each element of the original array. The provided function takes three arguments: the current element being processed, its index, and the array being processed. The `map()` function does not modify the original array.
261261

262262

263-
### filter function in JavaScript?
263+
### filter function ?
264264
The `filter()` function in JavaScript is an array method that creates a new array with all the elements that pass the test implemented by the provided function. The syntax for using `filter()` is:
265265

266266
```
@@ -280,7 +280,7 @@ console.log(filteredNumbers); // Output: [1, 3, 5]
280280
```
281281

282282

283-
### reduce function in JavaScript?
283+
### reduce function ?
284284
The `reduce()` function in JavaScript is a higher-order function that allows you to iterate over an array and accumulate the values into a single value. It takes a callback function as its first parameter, which is applied to each element in the array, and then returns the final accumulated value. The callback function takes two parameters: an accumulator (which starts with an initial value or the first element of the array) and the current element being iterated over. Here's an example usage:
285285

286286
```
@@ -295,7 +295,7 @@ console.log(sum); // output: 15
295295
In this example, the `reduce()` function adds up all the numbers in the `numbers` array and returns the accumulated sum, which is 15.
296296

297297

298-
### find function in JavaScript?
298+
### find function ?
299299
The `find()` function is a built-in method in JavaScript used to search for an element in an array that satisfies a provided condition. It takes in a callback function and returns the first element in the array that meets the condition specified by the callback, or undefined if no such element is found.
300300

301301
Syntax:
@@ -310,7 +310,7 @@ console.log(foundNumber); // output: 4
310310
```
311311

312312

313-
### findIndex function in JavaScript?
313+
### findIndex function ?
314314
The `findIndex` function in JavaScript is an array method that returns the index of the first element in the array that satisfies a provided testing function. If no such element is found, it returns -1. The syntax for using `findIndex` is as follows:
315315

316316
```
@@ -332,7 +332,7 @@ console.log(evenIndex); // Output: 0
332332
In this example, `findIndex` searches through the `arr` array and finds the first element that is even, which is 2 at index 0. Therefore, `evenIndex` is set to 0.
333333

334334

335-
### some function in JavaScript?
335+
### some function ?
336336
Sure, here are a few examples of functions in JavaScript:
337337

338338
1. `console.log()`: This function is used to print messages to the browser's console.
@@ -348,11 +348,11 @@ Example: `let numString = "42"; let numInt = parseInt(numString);`
348348
Example: `setTimeout(function() { console.log("Delayed message"); }, 1000);`
349349

350350

351-
### every function in JavaScript?
351+
### every function ?
352352
It is not possible to list every function in JavaScript as there are countless built-in functions and libraries, and new ones are constantly being developed by the community. However, there are some commonly used built-in functions that are essential for programming in JavaScript, such as `console.log()`, `setTimeout()`, `parseInt()`, `parseFloat()`, `Math.random()`, and many more. Additionally, developers can create their own custom functions to perform specific tasks or manipulate data in unique ways.
353353

354354

355-
### flat function in JavaScript?
355+
### flat function ?
356356
In JavaScript, a flat function is used to flatten a multidimensional array into a one-dimensional array. The flat() function returns a new array with all elements flattened recursively up to the specified depth (by default it flattens all levels). Here's an example:
357357

358358
```
@@ -363,7 +363,7 @@ const flattenedArr = arr.flat(); // [1, 2, 3, 4, 5, 6, 7]
363363
Note that the flat() function is only available in newer versions of JavaScript (ECMAScript 2019), so it may not be supported in older browsers. In that case, you can use a polyfill or a custom implementation to achieve the same result.
364364

365365

366-
### flatMap function in JavaScript?
366+
### flatMap function ?
367367
The `flatMap()` function in JavaScript is an array method that combines mapping and flattening into a single step. It takes each element in the array, applies a mapping function to it, and then flattens the result into a new array. The resulting array has the same length as the original array, but the elements may be different due to the mapping and flattening process. The `flatMap()` function can also be used to remove empty or undefined values from an array.
368368

369369

0 commit comments

Comments
 (0)