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" }
let techlist1= ['spring', 'java'];
let techlist2= ['javascript', 'nodejs', 'mongo'];
let fullstacklist= […techlist1, …techlist2];
console.log(fullstacklist);
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