I have a problem with using ${'variable'+i} in a loop function. My task is to call each function from a loop. I read about template literal but I can't find anything regarding to my problem.
I would like to use
${'variable'+i} // (it works in php but not in javascript)
I have tried to use this ` but it didn't work too.
Here is my code:
var call = new XMLHttpRequest();
call.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
var myObj = JSON.parse(this.responseText);
var jumlah = myObj.jumlah;
var varray = new Array();
for(i=1; i<=jumlah; i++){
varray.push(`${"myObj.namagame"+i}`);
}
}
}
call.open("GET","'.$GLOBALS['dirfile'].'/core/update.php?f=search&q="+str,true);
call.send();
Here is my JSON result
{"jumlah":3,"namagame1":"ark survival evolved","namagame2":"agents of mayhem","namagame3":"age of mythology"}
So then, I would like to get myObj.namagame1,myObj.namagame2,myObj.namagame3 that is why I use a loop function to get them then write them to the document.
Would you please to help me, I am sorry if my question is such a dumb one. Thank you