Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array concat spread operator

const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
Comment

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

let userName = { name: "John Doe" };
let userSex = { sex: "Male" };

let user = { ...userName, ...userSex };

console.log(user); // { name: "John Doe", sex: "Male" }

// Note: In a situation where one key has another property,
// the last property overrides the first instance:

let userName = { name: "John Doe" };
let userSex = { sex: "Female", name: "Jane Doe" };

let user = { ...userName, ...userSex }; // { name: "Jane Doe", sex: "Female" }
Comment

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 :: tricky javascript interview questions 
Javascript :: delete node from linked list 
Javascript :: nested json schema mongoose 
Javascript :: toast success 
Javascript :: how to add abutton component to drawer in react native 
Javascript :: How to return arguments in an array in javascript 
Javascript :: convert celsius to fahrenheit javascript 
Javascript :: how to find missing number in integer array of 1 to 100 in javascript 
Javascript :: blur js 
Javascript :: mouse position 
Javascript :: nuxt import css 
Javascript :: call a self executing function javascript 
Javascript :: ng select2 angular dropdown 
Javascript :: what is after.js 
Javascript :: extract text from a string javascript 
Javascript :: how to redirect to another page after clicking ok in alert 
Javascript :: axios delete request 
Javascript :: how to add footer in every page jspdf 
Javascript :: how to run cypress test 
Javascript :: Slice and Splice -Javascript 
Javascript :: how to get last item in array in javascript 
Javascript :: javascript iterate through object attributes 
Javascript :: js array push 
Javascript :: javascript combining arrays 
Javascript :: async await javascript push 
Javascript :: mongoose rename collection 
Javascript :: Add remove link dropzone 
Javascript :: numeral js 
Javascript :: js run command in terminal 
Javascript :: how to go back to previous route in next.js 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =