How to move a key value to an new array inside an object

From below object { "user": { "id": 9, "email": "abcd@example.com", }, "country": "USA", "first_name": "firstName", "last_name": "lastName", } How can we move first_name and last_name to a new array named names and push that into the same object as below { "user": { "id": 9, "email": "abcd@example.com", }, "country": "USA", "name": [ { "first_name": "firstName",… Read More How to move a key value to an new array inside an object

Not getting all the keys of nested object using Javascript

I am trying to fetch all the keys of one nested object using Javascript but as per my code its not working as expected. I am explaining my code below. let jsonObj = { “service”:[ { “name”:”restservice”, “device”:”xr-1″, “interface-port”:”0/0/2/3″, “interface-description”:”uBot testing for NSO REST”, “addr”:”10.10.1.3/24″, “mtu”:1024 } ], “person”: { “male”: { “name”: “infinitbility” },… Read More Not getting all the keys of nested object using Javascript

How to merge elements in objects inside of array and returned unique objects with updated data

my question is how I can merge elements in array of objects and return array with unique objects. I was trying to use reduce but it’s looks like I missing something and it’s time to ask for hint. So how you can see I need merge elements of boolean where false is default value and… Read More How to merge elements in objects inside of array and returned unique objects with updated data

remove the second occurrence of array object with same name

I have this array (java script array of objects) users=[{name:’arrow’,age:50,id:444} {name:’bow’,age:66,id:884} {name:’arrow’,age:30,id:99}, {name:’apple’,age:50,id:999} {name:’bow’,age:50,id:9669}] I want to remove second occurrence of same name , in this case , I want to remove {name:’arrow’,age:30,id:99} and {name:’bow’,age:50,id:9669} and retain first occurrences{name:’arrow’,age:50,id:444} and {name:’bow’,age:66,id:884} Resulting array should be : users= [{name:’arrow’,age:50,id:444} {name:’bow’,age:66,id:884}, {name:’apple’,age:50,id:999}] >Solution : const users =… Read More remove the second occurrence of array object with same name

How to add a new property with index value to an object array in JavaScript?

I am new to the forum and a beginner at JavaScript. Please look at my code below that I am facing a problem with in terms of the output – let myColor = ["Red", "Green", "White", "Black"]; console.log(myColor.toString()); console.log(myColor.join("+")); let strings = ["avengers", "captain america", "ironman", "black panther"]; const newStrings = strings.map(elements => { return… Read More How to add a new property with index value to an object array in JavaScript?