Skip to content
Advertisement

Remove duplicate json when creating hmtl from JSON

I’m trying to populate a div dynamically with data from JSON but want to avoid duplicates. The script below will give me 3 divs, 2 “standard” and one “special”.

How can I achieve without creating duplicate div?

JavaScript
JavaScript
JavaScript

Advertisement

Answer

The better way is to first get the array with unique objects on property type then you can use that new filtered array for rendering like in filterProductList:

JavaScript

Then use filterProductList to render the HTML in your page. Your code will look:

JavaScript
Advertisement