您可以使用它的物體,像數組...
<div id="propertydiv"></div>
<div id="valuediv"></div>
<script>
var student = [
{ name : "John Doe", age : "28", gender : "Male" },
{ name : "Nazmul", age : "22", gender : "Male"},
{ name : "Nadir", age : "6", gender : "Male"}
];
var randomObject = Math.floor(Math.random()*student.length);
var keys = Object.keys(student[randomObject]);
var randomKey = keys[Math.floor(Math.random()*keys.length)];
var randomValue = student[randomObject][randomKey];
document.getElementById("propertydiv").innerHTML = randomKey;
document.getElementById("valuediv").innerHTML = randomValue;
</script>
謝謝:)它的工作原理。 –