驼峰命名对像

function mapKeyToCamelCase(data) {
    // 参考答案
 
    const rename = (name) => {
 
        return name.split('_').reduce((pre, current) => {
 
            return pre + current[0].toUpperCase() + current.substring(1)
 
        });
 
    }
    let res = Array.isArray(data) ? [] : {};
    for (let i in data) {
 
        if (typeof data[i] === 'object' && data[i] !== null) {
 
            res[rename(i)] = mapKeyToCamelCase(data[i])
 
        } else {
 
            res[rename(i)] = data[i];
 
        }
 
    }
    return res;
 
}
上一篇:Circular view path would dispatch back to the current handler...This may be the result of an unspeci


下一篇:2021-10-23