I have a response like this:
I want to display the name of each object inside this HTML:
{subjects.map((item, i) => (
When calling Object.keys
it returns a array of the object's keys.
Object.keys({ test: '', test2: ''}) // ['test', 'test2']
When you call Array#map
the function you pass will give you 2 arguments;
When you want to get the data, you need to use item
(or in the example below keyName
) instead of i
{Object.keys(subjects).map((keyName, i) => (
-
key: {i} Name: {subjects[keyName]}
))}