Skip to content
Advertisement

How to get keys from json object in javascript [closed]

I have a json file:

JavaScript

Now I want to get a list of the keys of each “name” object. At the end there should be ths list

JavaScript

and save it into an array.

What i have tried

JavaScript

hope this is understanable?

Advertisement

Answer

for each data in the array (map) you want the ingredient part (.ingredients), extract the keys (Object.keys) and flatten the array (.flat())

JavaScript

You may prefer loop style. the only difference is flattening occurs with … operator.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement