Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

spread operator merge objects

 let a = {
    a: 1,
    b: true
}

let b = {
	y: 093,
	z: 'This is an object'
}

const c = {...a, ...b}
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

merge two objects without spread operator

const person = {
    name: "John Doe", 
    age: 24,
    location: "U.S.A"
}
const job = {
    title: "Full stack developer",
    location: "Remote"
}

const employee = Object.assign(person, job);

console.log(employee);
Comment

merge two objects without spread operator

//output
{
    name: "John Doe", 
    age: 24,
    location: "Remote",
    title: "Full stack developer"
}
Comment

merge two objects without spread operator

const person = {
    name: "John Doe",
    location: "Remote"
}
const job = {
    title: "Full stack developer",
    location: "Office"
}
const employee = {...person, ...job}

console.log(employee);
Comment

merge two objects without spread operator

{
  name: 'John Doe',
  location: 'Office',
  title: 'Full stack developer'
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: res.status 
Javascript :: share link to whatsapp javascript 
Javascript :: jquery get radio button checked 
Javascript :: template string javascript 
Javascript :: javascript remove empty array 
Javascript :: how to set dropdown value in jquery 
Javascript :: redux dev tools 
Javascript :: React best way of forcing component to update 
Javascript :: jquery get td value 
Javascript :: nodejs current timestamp 
Javascript :: javascript math.pow 
Javascript :: cdn react 
Javascript :: how to remove duplicate array object in javascript 
Javascript :: first and last char vowel reg exp same char 
Javascript :: python iterate json file 
Javascript :: cypress input value should be 
Javascript :: aos animation angular 
Javascript :: jquery add remove class timer 
Javascript :: append HTML elements in JavaScript 
Javascript :: select checked checkboxes javascript 
Javascript :: npm auth0-react 
Javascript :: datatables get all rows 
Javascript :: sequelize dialect 
Javascript :: json foreach in javascript 
Javascript :: chart.js chart is not defined 
Javascript :: react addeventlistener useeffect 
Javascript :: javascript getminutes 2 digits 
Javascript :: convert json string into json object 
Javascript :: Could not find the drag and drop manager in the context of ResourceEvents. Make sure to wrap the top-level component of your app with DragDropContext 
Javascript :: check if js property exists in class 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =