Skip to content

Commit 0bafb7b

Browse files
readme updated
1 parent 032fcc5 commit 0bafb7b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,39 @@ console.log(`average: ${avg}`);
7070
console.log(`sum is ${sum}`);
7171
console.log(`max num is : ${maxNum}`);
7272
```
73+
74+
> Add element to the end of an array
75+
76+
```js
77+
const arrOne = [1, 2, 3, 4, 5];
78+
const arrTwo = [9, 10];
79+
console.log("arr: ", arrOne);
80+
// [ 1, 2, 3, 4, 5 ]
81+
arrOne.push(6, 7);
82+
console.log("arr: ", arrOne);
83+
// [1, 2, 3, 4, 5, 6, 7]
84+
arrOne.push(arrTwo);
85+
console.log("arr: ", arrOne);
86+
// [ 1, 2, 3, 4, 5, 6, 7, [ 9, 10 ] ]
87+
```
88+
89+
> Add element to the beginning of an array
90+
91+
#### example-1
92+
93+
```js
94+
const arr= = ["john", "doe", "smith"];
95+
console.log(arrThree);
96+
arr.unshift("Steve");
97+
console.log(arrThree);
98+
```
99+
100+
#### example-2
101+
102+
```js
103+
const arrThree = ["john", "doe", "smith"];
104+
console.log(arrThree); //[ 'john', 'doe', 'smith' ]
105+
const arrFour = ["steve", "mike"];
106+
arrThree.unshift(...arrFour);
107+
console.log(arrThree); //[ 'steve', 'mike', 'john', 'doe', 'smith' ]
108+
```

0 commit comments

Comments
 (0)