I'm new to JavaScript. I have the following object:
let obj1 =
[{
'id': 1,
'longString': 'Joe - 2011-04-23T18:25:23.511Z'
},
{
'id': 2,
'longString': 'Mary - 2010-04-23T18:25:23.511Z'
}];
I want to split the longString key into 2 keys, and the value into 2 values.
Here is what I want to make:
let obj2 =
[{
'id': 1,
'name': 'Joe',
'date': '2011-04-23T18:25:23.511Z'
},
{
'id': 2,
'name': 'Mary',
'date': '2010-04-23T18:25:23.511Z'
}];
I've tried to do it in pieces, but I'm stuck with the first piece which is splitting the value of longString.
This works for string:
let v = 'Mary - 2010-04-23T18:25:23.511Z';
let w = v.split(' -', 1);
How do I make it work for an object? Or is there a totally different way to split property values? Also, do I need to write a loop to assign obj1 to obj2?
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)