You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 05_Day_Arrays/05_day_arrays.md
+9-14
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ An array is a collection of different data types which are ordered and changeabl
59
59
### How to create an empty array
60
60
61
61
In JavaScript, we can create an array in different ways. Let us see different ways to create an array.
62
-
It is very common to use *const* instead of *let* to declare an array variable. If you ar using const it means you do not use that variable name again.
62
+
It is very common to use _const_ instead of _let_ to declare an array variable. If you ar using const it means you do not use that variable name again.
63
63
64
64
- Using Array constructor
65
65
@@ -400,7 +400,7 @@ if(index === -1){
400
400
// we can use also ternary here
401
401
index ===-1?console.log('This fruit does not exist in the array'):console.log('This fruit does exist in the array')
402
402
403
-
// let us check if a avocado exist in the array
403
+
// let us check if an avocado exist in the array
404
404
let indexOfAvocado =fruits.indexOf('avocado') // -1, if the element not found index is -1
405
405
if(indexOfAvocado ===-1){
406
406
console.log('This fruit does not exist in the array')
@@ -521,18 +521,20 @@ Splice: It takes three parameters:Starting position, number of times to be remov
521
521
522
522
```js
523
523
constnumbers= [1, 2, 3, 4, 5]
524
-
525
-
console.log(numbers.splice()) // -> remove all items
524
+
numbers.splice()
525
+
console.log(numbers) // -> remove all items
526
526
527
527
```
528
528
529
529
```js
530
530
constnumbers= [1, 2, 3, 4, 5]
531
-
console.log(numbers.splice(0,1)) // remove the first item
531
+
numbers.splice(0,1)
532
+
console.log(numbers) // remove the first item
532
533
```
533
534
534
535
```js
535
-
constnumbers= [1, 2, 3, 4, 5, 6];
536
+
constnumbers= [1, 2, 3, 4, 5, 6]
537
+
numbers.splice(3, 3, 7, 8, 9)
536
538
console.log(numbers.splice(3, 3, 7, 8, 9)) // -> [1, 2, 3, 7, 8, 9] //it removes three item and replace three items
537
539
```
538
540
@@ -544,15 +546,13 @@ Push: adding item in the end. To add item to the end of an existing array we use
let [, secondPerson, , fourthPerson] =name// first and third person is omitted
111
+
let [, secondPerson, , fourthPerson] =names// first and third person is omitted
112
112
113
113
console.log(secondPerson, fourthPerson)
114
114
```
@@ -218,7 +218,7 @@ console.log(w, h, a, p)
218
218
20 10 200 undefined
219
219
```
220
220
221
-
If the key is not found in the object the variable will be assigned to undefined. In case, the key is not in the object we can give a default value during declaration. See the example.
221
+
If the key is not found in the object the variable will be assigned to undefined. Sometimes the key might not be in the object, in that case we can give a default value during declaration. See the example.
222
222
223
223
```js
224
224
constrectangle= {
@@ -229,7 +229,7 @@ const rectangle = {
229
229
let { width, height, area, perimeter =60 } = rectangle
//Lets create a function which give information about the person object with destructuring
317
+
//Let us create a function which give information about the person object with destructuring
318
318
constgetPersonInfo= ({
319
319
firstName,
320
320
lastName,
@@ -335,7 +335,7 @@ const getPersonInfo = ({
335
335
}
336
336
console.log(getPersonInfo(person))
337
337
/*
338
-
Asabeneh Yetayeh lives in Finland. He is 200 years old. He is an Instructor and Developer. He teaches HTML, CSS, JavaScript, React, Redux, Node, MongoDB, Python and D3.js. He speaks Amharic, English and a little bit of Suomi(Finnish)
338
+
Asabeneh Yetayeh lives in Finland. He is 250 years old. He is an Instructor and Developer. He teaches HTML, CSS, JavaScript, React, Redux, Node, MongoDB, Python and D3.js. He speaks Amharic, English and a little bit of Suomi(Finnish)
339
339
*/
340
340
```
341
341
@@ -373,7 +373,7 @@ Assess Test Result 4/1/2020 1:00 false
373
373
374
374
### Spread or Rest Operator
375
375
376
-
When we destructure an array we use the spread operator(...) to get the rest elements as array. In addition to that we use spread operator to spread arr elements to another array.
376
+
When we destructure an array we use the spread operator(...) to get the rest elements as array. In addition to that we use spread operator to spread array elements to another array.
377
377
378
378
### Spread operator to get the rest of array elements
0 commit comments