原始对象:
const obj={
user_id: 1,
user_name:'张三'
}
期望对象:
const obj={
id: 1,
userName:'张三'
}
实现方法:
const mapObj = {
user_id: "id",
user_name: "userName",
};
const newObj = Object.fromEntries(Object.entries(obj).map(([k, v]) => [mapObj[k]||k, v]))