My aim is to transfer leaderboard information from the server to the client-side JavaScript. This is the code on my server side:
const leaderboard = [[dog,cat],[car,bus],[foo,bar]]
const toJson = JSON.stringify(leaderboard)
res.render('games/dodge.ejs', {
leaderboard: toJson
})
This is how the ejs file receives it:
<div data-leaderboard="<%= leaderboard%>"></div>
Next, there is the client-side JavaScript file dodge_leaderboards.js
const leaderboardData = document.querySelector("[data-leaderboard]")
console.log(leaderboardData)
Upon running this code, I encounter an error that states Uncaught SyntaxError: Identifier 'leaderboardData' has already been declared (at dodge_leaderboards.js:1:1). Additionally, the console.log returns null.
I am attempting to assign the arrays within the larger array to individual variables, but now I am facing issues with a simple console.log. What do you think might be causing this problem? I am also curious to learn how to parse the array.