I have two arrays which im checking against in a for loop, but am stuck on how to make the for loop work on the array.
The array is build like this in json_encode:
var bdata = {"1":["50","50","0","Player1"],"2":["1500","1000","1000","Player2"]};
The array i am comparing it against is encoded like this:
var vdata = {"uid":"1","total":"1","w":"1","t":"1","s":"1","g":"1","l":"0","upd":"0"};
Then i tried to create the loop by converting them into arrays but it does not work:
bdata = JSON.parse(bdata);
vdata = JSON.parse(vdata);
for(bdata[0] as bid){
if(vdata["w"] >= bdata[bid][1] && vdata["g"] >= bdata[bid][0] && vdata["s"] >= bdata[bid][2]){
document.getElementById(id).innerHTML += "<br/>"+bdata[bid][3];
}else{
document.getElementById(id).innerHTML += "<br/><font color='red'>"+bdata[bid][3]+"</font>";
}
}
But the error i get is : Unexpected identifier
I’m not even sure im looping the first array correctly ?
Plenty of syntax errors. For example
For loop syntax. Either use
or
Greater-than-or-equal-to comparison operator
not
You don’t need to use
JSON.parse(), you already have JSON objects