Author -  Sai gowtham

Clone or merge objects using Object.assign() in JavaScript

Object.assign( ) method help us to copy the values of all enumerable properties from the one or more source objects to the target object.It returns the target object.

Syntax:

Object.assign(target, source);

Merging two objects

In this example, we are merging user and posts object into a single object using Object.assign() method.

const user = {
  id:1,
  name:"gowtham"
}

const posts = {
  title:"my post",
  body:"demo"
}


console.log(Object.assign(user, posts));

// {body: "demo", id: 1, name: "gowtham", title: "my post"}

Merge and overwrite the same properties

We can also merge and overwrite the same property names using Object.assign().

const user1 = {
  id:1,
  name:"gowtham"
}

const user2 = {
  id:2,
  name:"sai"
}

const user3 = {
  id:3,
  name:"tony"
}

console.log(Object.assign(user1, user2, user3));

// {id: 3, name: "tony"}

Cloning Objects

const user = {
  id:16,
  name:"gowtham"
}

const cloneuser = Object.assign({}, user);

console.log(cloneuser); // {id: 16, name: "gowtham"}

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY