方法一:Object.values(obj)
示例:
var obj = { name: '小明', age: 22 };
console.log( Object.values(obj) ); // ['小明', 22]
方法二:for-in循环
示例:
var obj = { name: '小明', age: 22 };
var arr = [];
let objName = [];
for(let i in obj) {
arr.push (obj[i]) //获取属性值
objName.push(i) //获取属性名
}
console.log(arr); // ['小明', 22]
console.log(objName); //['name', 'age']
运行结果如下: