通过for in获取对象属性名和属性值
const object = { label: '张三', value: '111111', } for (const key in object) { if (Object.hasOwnProperty.call(object, key)) { const value = object[key] console.log(key) //属性名 console.log(value) //属性值 } }
通过for in获取对象属性名和属性值
const object = { label: '张三', value: '111111', } for (const key in object) { if (Object.hasOwnProperty.call(object, key)) { const value = object[key] console.log(key) //属性名 console.log(value) //属性值 } }