|
|
|
@ -788,18 +788,20 @@ Splice: It takes three parameters:Starting position, number of times to be remov
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const numbers = [1, 2, 3, 4, 5]
|
|
|
|
|
|
|
|
|
|
console.log(numbers.splice()) // -> remove all items
|
|
|
|
|
numbers.splice(0, numbers.length) // -> remove all items
|
|
|
|
|
console.log(numbers) // -> []
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const numbers = [1, 2, 3, 4, 5]
|
|
|
|
|
console.log(numbers.splice(0, 1)) // remove the first item
|
|
|
|
|
numbers.splice(0, 1) // remove the first item
|
|
|
|
|
console.log(numbers) // -> [2, 3, 4, 5]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const numbers = [1, 2, 3, 4, 5, 6]
|
|
|
|
|
console.log(numbers.splice(3, 3, 7, 8, 9)) // -> [1, 2, 3, 7, 8, 9] //it removes three item and replace three items
|
|
|
|
|
numbers.splice(3, 3, 7, 8, 9) // it removes three item and replace three items
|
|
|
|
|
console.log(numbers) // -> [1, 2, 3, 7, 8, 9]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
##### Adding item to an array using push
|
|
|
|
|