给定一个JavaScript对象,如何将其转换为对象数组(每个对象都带有键,值)?
例:
var data = { firstName: 'John', lastName: 'Doe', email: 'john.doe@gmail.com' }
结果像:
[ { key: 'firstName', value: 'John' }, { key: 'lastName', value: 'Doe' }, { key: 'email', value: 'john.doe@gmail.com' } ]
var data = { firstName: ‘John’, lastName: ‘Doe’, email: 'john.doe@gmail.com‘ }
var output = Object.entries(data).map(([key, value]) => ({key,value})); console.log(output);