Skip to content

Commit 42494c5

Browse files
authored
Merge pull request sadanandpai#48 from prajwalkulkarni/main
Additional ways to empty an array - Q5
2 parents 2c6e9f5 + ee25286 commit 42494c5

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

challenges/collections-concepts.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,15 @@ console.log(arr); // [1, 2, 3, 4, 5]
140140

141141
- Array can be emptied by giving a new reference of an empty array
142142
- Setting the `length` of the array to 0 will automatically makes the array empty
143-
- `pop` operation on array can also be used to empty the array where each elements get removed
143+
- `pop` and `shift` operation on array can also be used to empty the array where each elements get removed
144144

145145
```js
146146
arr = [];
147147
```
148148

149+
```js
150+
arr = new Array()
151+
```
149152
```js
150153
arr.length = 0;
151154
```
@@ -156,6 +159,12 @@ while(arr.length > 0){
156159
}
157160
```
158161

162+
```js
163+
while(arr.length > 0){
164+
arr.shift()
165+
}
166+
```
167+
159168
```js
160169
arr.splice(0, arr.length)
161170
```

0 commit comments

Comments
 (0)