I have the following objects
var obj1 =
[
{
"id": 1373744172,
"name": "Run",
"distance": 6051.8,
"date": "2018-01-24T16:43:09Z",
},
{
"id": 1370355715,
"name": "Swim",
"distance": 1043,
"date": "2018-01-22T21:10:28Z",
}
]
var dest =
[
{title: "Placeholder", body: "1900-01-01T00:00:00Z"}
]
I am trying to overwrite the dest based on obj1, so I should end up with
[
{title: "Run", body: "2018-01-24T16:43:09Z"},
{title: "Swim", body: "2018-01-22T21:10:28Z"}
]
I've looked at Object.assign, and for-in loops, but I've not yet figured out the right approach. e.g.
var obj1 =
[
{
"id": 1373744172,
"name": "Run",
"distance": 6051.8,
"date": "2018-01-24T16:43:09Z",
},
{
"id": 1370355715,
"name": "Swim",
"distance": 1043,
"date": "2018-01-22T21:10:28Z",
}
]
var dest =
[
{title: "Placeholder", body: "1900-01-01T00:00:00Z"}
]
Object.assign(dest, {title: obj1.name, body: obj1.date});
console.log(JSON.stringify(dest));
I'm sure this must have been asked and answered before, but I don't seem to be searching with the right terms!
<>toolbar button) to make it runnable (here's how to do one). More: How do I ask a good question?dest, or do you want a new array? (In the former case other references to the old array would see the updates; in the latter they wouldn't.)dest