I have the following code;
namedarray[\'India\']=\'New Delhi\';
namedarray[\'Australia\']=\'Canberra\';
namedarray[\'Indonasia\']=\'Jakarta\';
namedarray[\'I
Try this:
function fetch_random(obj) {
var temp_key, keys = [];
for(temp_key in obj) {
if(obj.hasOwnProperty(temp_key)) {
keys.push(temp_key);
}
}
return obj[keys[Math.floor(Math.random() * keys.length)]];
}
var random_name = fetch_random(namedarray);
document.getElementById('question').innerHTML="Q." + random_name +" is capital for which country"