使用 Object.values()
通过使用 Object.values(),任何 JavaScript 对象都可以被转换为数组:
const person = {
name: "John",
age: 30,
city: "New York"
};
const myArray = Object.values(person);
myArray 现在是 JavaScript 数组,可以显示了:
实例
const person = {
name: "John",
age: 30,
city: "New York"
};
const myArray = Object.values(person);
document.getElementById("demo")。innerHTML = myArray;
如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h64466.shtml