数组对象格式化
const newData = this.selectData.map(e=> { const item = this.formatKey(e) return item }) formatKey(obj) { const keys = Object.keys(obj); const newObj = {}; keys.forEach(key => { const camelCaseKey = key.replace(/_([a-z])/g, (m, p1) => p1.toUpperCase()); newObj[camelCaseKey] = obj[key]; }); return newObj; },
对象格式化
const newData = {};
for (const [key, value] of Object.entries(this.selectData[0])) {
const newKey = key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
newData[newKey] = value;
}