I have forgotten most of what I learnt so treat ma as a novice. 🙁
I have an object of arrays returned from a database select statement as below :-
options:[{"breed":"bulldog"},{"breed":"labrador"}{"breed":"beagle"},{"breed":"dobermann"}]
Using javascript, how can I transpose this into an array as below :-
const breed ["bulldog","labrador","beagle","dobermann"];
The array will be used to populate a node-red dropdown menu.
Thanks for looking or advising.
I have tried split and map, but I cant seem to arrive at my required.
Maybe because I did not code it correctly.
2
Answers
You’ll need to
map()
over the array, and then select thebreed
key of each object.If you can’t use a hard-coded
breed
key, you can useObject.values()
withflatMap()
:Object.values
is probably the best way…