I'm trying to extract some of the items from an object. If I'm not wrong, I need to use for...in to loop the object items.
let myObject = {
id: 1,
company: "Apple",
product: {
name: "iPhone",
price: "100",
releaseDate: "01 Jan 2019",
color: {
black: "#000000",
silver: "#C0C0C0",
}
}
}
for (property in myObject) {
console.log(`${property} = ${myObject[property]}`);
}
How can I only get the product
's name
and price
only?
Expected result:
newArray = [
name: "iPhone",
price: 100,
]