This commit is contained in:
Ilya Kantor 2019-10-10 17:29:27 +03:00
parent 7418213b66
commit 6d44c1e1ac
5 changed files with 7 additions and 8 deletions

View file

@ -160,13 +160,13 @@ For instance:
let arr = [1, 2];
// create an array from: arr and [3,4]
alert( arr.concat([3, 4])); // 1,2,3,4
alert( arr.concat([3, 4]) ); // 1,2,3,4
// create an array from: arr and [3,4] and [5,6]
alert( arr.concat([3, 4], [5, 6])); // 1,2,3,4,5,6
alert( arr.concat([3, 4], [5, 6]) ); // 1,2,3,4,5,6
// create an array from: arr and [3,4], then add values 5 and 6
alert( arr.concat([3, 4], 5, 6)); // 1,2,3,4,5,6
alert( arr.concat([3, 4], 5, 6) ); // 1,2,3,4,5,6
```
Normally, it only copies elements from arrays. Other objects, even if they look like arrays, are added as a whole:
@ -180,7 +180,6 @@ let arrayLike = {
};
alert( arr.concat(arrayLike) ); // 1,2,[object Object]
//[1, 2, arrayLike]
```
...But if an array-like object has a special `Symbol.isConcatSpreadable` property, then it's treated as an array by `concat`: its elements are added instead: