I have some api data that is being returned as an object:
{
"name": "Luke Skywalker",
"height": "172",
"mass": "77",
"hair_color": "blond",
"skin_color": "fair",
"eye_color": "blue",
"birth_year": "19BBY",
"gender": "male"
}
I have a list of keys in a configuration array that I am interested to extract from the original response:
let attributes = ['name', 'height', 'mass'];
How do i use the attribute array to give me an object back like so:
{
"name": "Luke Skywalker",
"height": "172",
"mass": "77"
}
let { name, height, mass } = objectWithTheseProperties;Or if you don't know if the object has the property in question you can useif (theObjectInQuestion.hasOwnProperty(propertyInQuestion)) { // do stuff };