My goal is to extract JSON values and create variables from them, but I keep encountering an error. Even when the JSON array is filled, I still face issues.
var tempArray = [];
$("#sth td").each(function(){
$this = $(this);
tempArray.push({"COLOR":$this.attr("data-color"),});
});
console.log(JSON.stringify(tempArray));
if(tempArray != null) var color = tempArray[c-1].COLOR;
Can someone explain why I am getting this error in the last line:
Uncaught TypeError: Cannot read property 'COLOR' of undefined