I working in d3.js and I created this object with the values I need. Then when I go to draw the d3 line, the values have mysteriously changed to the 0 value when I originally initiated the value.
It is so odd, because I can do console.log(d)
and depending on if the object is collapsed or expanded in the console it will show different values for d.my_count
.
See this screenshot of the spooky behavior:
Here is how I'm incrementing(changing) those values:
dataset.then(function(data) {
//loop through all the data
data.map(function (d){
//round the score
var rating = Math.round(d.average_rating)
//bump up max rating if needed
if(rating > maxRating){maxRating = rating};
if(years.includes(d.year)){
tmpIndex = indexByYear(d.year)
ratingCountByYear[tmpIndex][rating]['my_count'] += 1;
}
})
})
See the line that says: ratingCountByYear[tmpIndex][rating]['my_count'] += 1;
? That is the line that apparently makes the change to my ratingCountByYear
object. But it will only show up in the console as the changed value WHEN EXPANDED.
This is the console in Firefox. Chrome is exhibiting a similar behavior, except the expanded and collapsed view show the values I want, while trying to access the values always gives me the instantiated value (I know because I've tried to change the instantiation, and only the instantiated value comes across when I try and access it)
What in the world is going on? I assume some sort of issue with how the objects are kept in memory under the hood?!?!?