Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

combine two arrays javascript

let arr1 = [0, 1, 2];
let arr2 = [3, 5, 7];
let primes = arr1.concat(arr2);

// > [0, 1, 2, 3, 5, 7]
Comment

javascript combine array of arrays

/* Flatten (merge) an array of arrays with reduce & concat */
let myArrays = [[1, 2, 3], [4, 5], [6]];
myArrays.reduce((initial, current) => initial.concat(current), []);
// → [1, 2, 3, 4, 5, 6]


/* Join multiple arrays together. */
let warm = ["red", "orange"];
let cool = ["blue", "purple"];
let neutral = ["brown", "gray"];
let colors = warm.concat(cool).concat(neutral);
// → ["red", "orange", "blue", "purple", "brown", "gray"]
Comment

javascript merge array

// ES5 version use Array.concat:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = array1.concat(array2);
// combinedArray == ["a", "b", "1", "2"]

// ES6 version use destructuring:
let array1 = ["a", "b"]
let array2 = ["1", "2"]
let combinedArray = [...array1, ...array2]
// combinedArray == ["a", "b", "1", "2"]
Comment

combine 2 arrays javascript

//ES6 using the spread operator
const itemsA = [ 'Lightsaber', 'Mockingjay pin', 'Box of chocolates' ];
const itemsB = [ 'Ghost trap', 'The One Ring', 'DeLorean' ]
const allItems = [ ...itemsA, ...itemsB ];
Comment

javascript how to merge arrays

const arrFirst = ['string1', 'string2'];
const arrSecond = ['string3','string4'];

const newArr = [...arrFirst, ...arrSecond];

console.log(newArr);
Comment

js join two arrays

[1,2,3].concat([4,5,6])
// [1,2,3,4,5,6]
Comment

js combine two arrays

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

letters.concat(numbers);
// result in ['a', 'b', 'c', 1, 2, 3]
Comment

PREVIOUS NEXT
Code Example
Javascript :: File is a CommonJS; it may be converted to an ES6 module 
Javascript :: relative width and height image react native 
Javascript :: how to write img jsx 
Javascript :: js sound 
Javascript :: js functions inside of objects 
Javascript :: Regex match word js 
Javascript :: knockout dump variable 
Javascript :: angular filter array of objects 
Javascript :: array filter falsy values 
Javascript :: js select disabled 
Javascript :: onclick checkbox hide div and unchecked show div 
Javascript :: javascript remove duplicate in two arrays 
Javascript :: how to change active tab jquery 
Javascript :: unpack list javascript 
Javascript :: javascript substring after character 
Javascript :: angular convert response to json 
Javascript :: form submit programmatically 
Javascript :: slice string javascript from index to space 
Javascript :: js replace characters in a string 
Javascript :: implement the remove property function 
Javascript :: drupal 8 get node from form 
Javascript :: color console 
Javascript :: create number pyramid in javascript 
Javascript :: s3 list objects in folder node js 
Javascript :: remove duplicates from array of objects javascript 
Javascript :: image base64 to file javascript 
Javascript :: toggle class javascript and jquery 
Javascript :: ffmpeg convert mp4 to avi 
Javascript :: generate random string javascript 
Javascript :: call javascript function after div load 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =