js对象键值对转换为数组对象

原对象:
{
   SF: '顺丰速运',
   DBL: "德邦快递"  
}
转换后:
[{
    label: "顺丰速运"
    value: "SF"
  },{
    label: "德邦快递"
    value: "DBL"
  }]
源码:
const obj = {
  SF: '顺丰速运',
  DBL: "德邦快递"  
}
const result = Object.keys(obj).map((el) => {
  return {
     value: el,
     label: obj[el]
  }
})
console.log(result)

你可能感兴趣的:(js对象键值对转换为数组对象)