Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript merge two array with spread operator

const a = ['to', 'code'];
const b = ['learning', ...a, 'is', 'fun']; 
console.log(b); //> ['learning', 'to', 'code', 'is', 'fun']
Comment

Merging Or Copying Arrays Using Spread Operator

let techlist1= ['spring', 'java'];
 let techlist2= ['javascript', 'nodejs', 'mongo'];
 let fullstacklist= […techlist1, …techlist2];
 console.log(fullstacklist);
Comment

How to Concatenate or Merge Arrays With the Spread Operator in JavaScript

let femaleNames = ["Daniel", "Peter", "Joe"];
let maleNames = ["Sandra", "Lucy", "Jane"];

let allNames = [...femaleNames, ...maleNames];

console.log(allNames); // ["Daniel","Peter","Joe","Sandra","Lucy","Jane"]

// It's also important to know that we can use the same approach for as many arrays
// as we have. We can also add individual elements within the array:

let femaleNames = ["Daniel", "Peter", "Joe"];
let maleNames = ["Sandra", "Lucy", "Jane"];
let otherNames = ["Bill", "Jill"];

let moreNames = [...otherNames, ...femaleNames, ...maleNames];
let names = [...moreNames, "Ben", "Fred"];


// This saves us the stress of using a complicated syntax like the concat() method
Comment

PREVIOUS NEXT
Code Example
Javascript :: listen to all events on an html element 
Javascript :: shell 
Javascript :: lowercase 
Javascript :: Install PHP debugbar 
Javascript :: js localstorage clear 
Javascript :: how to uninstall nodejs web server 
Javascript :: jquery dom traversal parent 
Javascript :: nesting express routes 
Javascript :: send data using axios 
Javascript :: add table header dynamically in jquery 
Javascript :: concat no and string in javascript 
Javascript :: how to delete a parameter with js 
Javascript :: how to name a javascript variable 
Javascript :: visual studio code json to one line 
Javascript :: send response from iframe to parent 
Javascript :: react date picker 
Javascript :: scroll top javascript 
Javascript :: changement image js sur click 
Javascript :: add spinner angular 13 loading 
Javascript :: fullcalendar edit event modal react 
Javascript :: why to use arrow functions over normal function 
Javascript :: how to change data value in jquery 
Javascript :: padend javascript 
Javascript :: time complexity of slice javascript 
Javascript :: disable js on chrome 
Javascript :: eval javascript 
Javascript :: create random password 
Javascript :: change form value dynamically angular 
Javascript :: what is weakmap and weakset in javascript 
Javascript :: address validation in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =