Array js concat

Príklady kódu

14
0

N

//ES6
const array3 = [...array1, ...array2];
13
0

N


let chocholates = ['Mars', 'BarOne', 'Tex'];
let chips = ['Doritos', 'Lays', 'Simba'];
let sweets = ['JellyTots'];

let snacks = [];
snacks.concat(chocholates);
// snacks will now be ['Mars', 'BarOne', 'Tex']
// Similarly if we left the snacks array empty and used the following
snacks.concat(chocolates, chips, sweets);
//This would return the snacks array with all other arrays combined together
// ['Mars', 'BarOne', 'Tex', 'Doritos', 'Lays', 'Simba', 'JellyTots']
6
0

N

const array1 = ['a', 'b', 'c'];
const array2 = ['d', 'e', 'f'];
const array3 = array1.concat(array2);

console.log(array3);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
6
0

N

const letters = ['a', 'b', 'c'];
const numbers = [1, 2, 3];

const newArray = letters.concat(numbers);
// newArrat is ['a', 'b', 'c', 1, 2, 3]
3
0

N

let fruits = ["apples", "bananas"];
let vegetables = ["corn", "carrots"];
let produce = [...fruits, ...vegetables];
//["apples","bananas","corn","carrots"]
-2
0

N

// using push and apply to return the same array
const arr1 = ['a', 'b'];
const arr2 = ['c', 'd'];
arr1.push.apply(arr1, arr2);
console.log(arr1) // ['a', 'b', 'c', 'd']

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................