[Editing and updating my answer. The other answers seem to overlap with mine pretty much, but, I thought I have another ago and provide an alternative].
I present 3 solutions to this problem, based on:
- Object.keys
- Object.values
- Object.entries
Objects.keys() solution:
let keys = Object.keys(dataObject); // ["object1", "object2", "object3" ];
let keysToResult = keys.map( e => dataObject[e] ); // [{"id":1,"name":"Fred"},{"id":2,"name":"Wilma"},{"id":3,"name":"Pebbles"}]
Object.values solution:
let values = Object.values(dataObject); // [{"id":1,"name":"Fred"},{"id":2,"name":"Wilma"},{"id":3,"name":"Pebbles"}]
Object.entries solution:
let entries = Object.entries(dataObject); // [["object1",{"id":1,"name":"Fred"}],["object2",{"id":2,"name":Wilma"}],["object3",{"id":3,"name":"Pebbles"}]]
let entriesToResult = entries.map( ([k,v]) => v ); [{"id":1,"name":"Fred"},{"id":2,"name":"Wilma"},{"id":3,"name":"Pebbles"}]
All three solutions have their own features.
Object.keys() returns an array with insufficient result. So, we use Array.prototype.map to top up each value in the array to get close to what we want. In general, we can think of Object.keys() combined with map as a mechanism to customize our result list with what we want.
Object.values() is interesting since it discards the key and just returns the results only. In fact, for this problem, this is perfect since the answer requires no further processing.
Object.entries() returns more than what we want since it returns both keys and values. We need to use map to customize our result. In fact, we need to cut out the excess information.
Object.keys(), Object.values() and Object.entries() are all very useful functions which is why I wanted to show all 3 as a solution to this problem. Depending on your specific use case, you may find one to a better fit to solving your problem.