如果把这个话题局限在你提供的DEMO中的话,并且以通用方法来解读的话:
Array.prototype.toCamelCase = function(keys) {
keys = keys || { CARID: 'carId', CARNO: 'carNo' };
return this.map(item => {
let newItem = {};
for (let ii in item) {
newItem[keys[ii] || ii] = item[ii];
}
return newItem;
});
}
console.log(JSON.stringify(data.toCamelCase()));
// [{"carId":"111","carNo":"1111"},{"carId":"222","carNo":"2222"},{"carId":"333","carNo":"3333"}]
console.log(JSON.stringify(data.toCamelCase({ CARID: 'carID', CARNO: 'carNO' })));
// [{"carID":"111","carNO":"1111"},{"carID":"222","carNO":"2222"},{"carID":"333","carNO":"3333"}]
再超就难了。
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…