I have this array that I get from the serve:
dataFromServer = [
{
created_date: "02/10/2019"
date_of_birth: "01/01/2000"
email: "test@test.com"
first_name: "test"
last_name: "test"
mobile_phone: "999-999-9999"
registration_id: "3344"
},
{
created_date: "02/10/2015"
date_of_birth: "01/01/1980"
email: "test2@test2.com"
first_name: "test2"
last_name: "test2"
mobile_phone: "111-222-333"
registration_id: "123"
}
]
and I have to put it in another array to get rid of the "_" in between each property. So this is what I'm doing:
const newArray = []
dataFromServer.foreach(obj => {
newArray.push(
{
lastName: obj.last_name,
firstName: obj.first_name,
dateOfBirth: obj.date_of_birth,
registrationId: obj.registration_id,
createdDate: obj.created_date,
email: obj.email,
mobile_phone: obj.mobile_phone
});
});
Is there a better/ clear way in pure javascript (maybe using destructuring) or using Lodash? Thank a lot!