mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 05:24:10 +03:00
Added mutable chart to javascript cheatsheet
This commit is contained in:
1 parent
16174c4325
commit
14ccefde8d
1 file changed
+29
-4
+29
-4
@@ -515,6 +515,7 @@ cart.push('pear');
|
||||
const numbers = [1, 2];
|
||||
numbers.push(3, 4, 5);
|
||||
```
|
||||
Add items to the end and returns the new array length.
|
||||
|
||||
|
||||
### Method .pop()
|
||||
@@ -525,18 +526,42 @@ const a= ['eggs', 'flour', 'chocolate'];
|
||||
const p = a.pop(); // 'chocolate'
|
||||
console.log(a); // ['eggs', 'flour']
|
||||
```
|
||||
Remove an item from the end and returns the removed item.
|
||||
|
||||
|
||||
### Mutable
|
||||
### Method .shift()
|
||||
|
||||
```javascript
|
||||
const names = ['Alice', 'Bob'];
|
||||
let cats = ['Bob', 'Willy', 'Mini'];
|
||||
|
||||
names.push('Carl');
|
||||
// ['Alice', 'Bob', 'Carl']
|
||||
cats.shift(); // ['Willy', 'Mini']
|
||||
```
|
||||
Remove an item from the beginning and returns the removed item.
|
||||
|
||||
|
||||
### Method .unshift()
|
||||
|
||||
```javascript
|
||||
let cats = ['Bob'];
|
||||
|
||||
// => ['Willy', 'Bob']
|
||||
cats.unshift('Willy');
|
||||
|
||||
// => ['Puff', 'George', 'Willy', 'Bob']
|
||||
cats.unshift('Puff', 'George');
|
||||
```
|
||||
Add items to the beginning and returns the new array length.
|
||||
|
||||
|
||||
### Mutable chart
|
||||
| | add | remove | start | end |
|
||||
|:----------|:---:|:------:|:-----:|:---:|
|
||||
| `push` | ✔ | | | ✔ |
|
||||
| `pop` | | ✔ | | ✔ |
|
||||
| `unshift` | ✔ | | ✔ | |
|
||||
| `shift` | | ✔ | ✔ | |
|
||||
{.show-header}
|
||||
|
||||
|
||||
JavaScript Loops {.cols-3}
|
||||
------------
|
||||
|
||||
Reference in new issue
Block a user