To extract the property values of a JavaScript object into an array, we use the Object.values
method.
For instance, we write
const dataObject = {
object1: {
id: 1,
name: "Fred",
},
object2: {
id: 2,
name: "Wilma",
},
object3: {
id: 3,
name: "Pebbles",
},
};
const valuesOnly = Object.values(dataObject);
to call Object.values
with dataObject
to return the property values of dataObject
in an array.