mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 13:34:06 +03:00
Added concat()
This commit is contained in:
1 parent
14ccefde8d
commit
b820667719
1 file changed
+24
-8
+24
-8
@@ -504,6 +504,16 @@ console.log(myArray[1]); // 200
|
||||
```
|
||||
|
||||
|
||||
### Mutable chart
|
||||
| | add | remove | start | end |
|
||||
|:----------|:---:|:------:|:-----:|:---:|
|
||||
| `push` | ✔ | | | ✔ |
|
||||
| `pop` | | ✔ | | ✔ |
|
||||
| `unshift` | ✔ | | ✔ | |
|
||||
| `shift` | | ✔ | ✔ | |
|
||||
{.show-header}
|
||||
|
||||
|
||||
### Method .push()
|
||||
|
||||
```javascript
|
||||
@@ -553,14 +563,20 @@ 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}
|
||||
|
||||
|
||||
### Method .concat()
|
||||
```javascript
|
||||
const array = [3, 2, 1]
|
||||
const newFirstElement = 4
|
||||
|
||||
// => [ 4, 3, 2, 1 ]
|
||||
[newFirstElement].concat(array)
|
||||
|
||||
// => [ 3, 2, 1, 4 ]
|
||||
[array].concat(newFirstElement)
|
||||
```
|
||||
if you want to avoid mutating your original array, you can use concat.
|
||||
|
||||
|
||||
JavaScript Loops {.cols-3}
|
||||
|
||||
Reference in new issue
Block a user