Skip to content
Advertisement

How to output an array individually for each object in JSON using JS?

The for (let pet of person.pets) does not output as expected. It is an array in the JSON. Instead of a single array, I get all the pet arrays for all objects in my JSON file. I just want one array per object listed in the JSON-example below.

JavaScript
JavaScript

Advertisement

Answer

$('.person').append() appends to all .person elements. You should just append to the person element you just added.

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