Skip to content
Advertisement

Getting an uncaught error when trying to print an data array object in JavaScript

So I’m new to JS and doing an exercise where I wanna create a shopping cart. The requirement is to use “dynamic data source” and not hardcode attributes into the HTML so I’ve created this object that I want to just display in my HTML, for example the description, the image etc.. I got everything to work with “static” attributes in the HTML following a tutorial, but I wanna use a data-source instead since that is a more real case, where you’d update the data source and that would then automatically be updated on the webpage.

The error message is that I’ve declared the same variable twice but I dont really understand how? Since I only call products and don’t declare it again… also it just prints “object object object” in my HTML.

Uncaught SyntaxError: Identifier ‘products’ has already been declared (at store.js:1:1)

JavaScript
JavaScript

Advertisement

Answer

You can check the below implementation with dynamic headers and rows

I also left some useful comments there to solve possible issues you’re facing

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