How can I add only particular key value pairs from one object to another?

Umang Mehra

suppose,

obj1 = 
0: {
description: "",
holiday: false,
id: "",
isWeekend: false,
percent: 0,
pmDescription: "",
pmHours: 0,
productivity: 0,
projectName: "rgffgfg",
sowId: "7396",
time: 1591641000000,
userHours: 0,
userName: "hemant tripathi",
wfh: false,
},
1: {
description: "",
holiday: false,
id: "",
isWeekend: false,
percent: 0,
pmDescription: "",
pmHours: 0,
productivity: 0,
projectName: "rgffgfg",
sowId: "7396",
time: 1591641000000,
userHours: 0,
userName: "hemant tripathi",
wfh: false,
}
2: {
description: "",
holiday: false,
id: "",
isWeekend: false,
percent: 0,
pmDescription: "",
pmHours: 0,
productivity: 0,
projectName: "rgffgfg",
sowId: "7396",
time: 1591641000000,
userHours: 0,
userName: "hemant tripathi",
wfh: false,
}


obj2: {}

I just want to add 3 key-value pairs in obj2. I want to loop through and access obj1. And add only 3 key-value pairs in obj2 ('description' , 'userHours' , 'userName') .I want to add these 3 key-value pairs. How can we do that?

dipendra
let obj1= [{
description: "",
holiday: false,
id: "",
isWeekend: false,
percent: 0,userHours: 0,userName: 'Ab'
},
{
description: "",
holiday: false,
id: "",
isWeekend: false,
percent: 0,userHours: 0,userName: 'Abcd'
}];

let obj2 = obj1.map(data => ({description: data.description, userHours: data.userHours, userName: data.userName}));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Have an array of objects, need to add new object. How do I check if only one of key: value pairs exist

How can I create a new object that only contains the key/value pairs specified in an array?

How can I add values in key value pairs generated in scala

How to add a value from one table to a particular row in another table?

exclude specific key/value pairs by key name when copy contents from one object to another

How can I create a table from key-value pairs?

How can I extract these key/value pairs from this JSON node?

How can I define an object type with one value if the key is in an array and another value if not

How to check particular object key is exist as a value of another object key?

How to take particular key value pairs from json array

How can I add a value to an array's key from another array with the same key in PHP?

Check for particular value from class object and get the value of another key

How I can add key/value to the object in object?

How to add and delete a missing key value from one list to another

How to copy dictionary object value from one key to another?

How can I create key-value pairs object where value is component?

JS - How to add key:value pairs from objects nested in arrays to other objects nested in another array

How can I get fields from one object and add them to another in Javascript?

add key value pairs to object from an array - Javascript

How can I add the data of one JS object to another

How can I use jq to get the key value pairs only and set as environment variable?

How to send object key value pairs that contain values only?

How can I add a key/value pair to a JavaScript object?

How can I add a new key with a value to an object in TypeScript?

How can I get only one value from Angular FromGroup as an object?

How to I add contents from one object to another?

How to add types for object with varying number of key/value pairs?

How to dynamically add key value pairs in Kotlin object?

How can I query a table with key/value pairs into a JSON object using FOR JSON PATH?