const res = {} function transform(res, obj, str) { const keys = Object.keys(obj) for(let i = 0;i < keys.length;i++) { const key = keys[i] const value = obj[key] const k = str === '' ? keys[i] : str+'.'+keys[i] if(typeof value !== 'object') { // value如果不是对象是数值或者是字符串的 res[k] = value continue } if(Array.isArray(value)) { arrHelper(res, value, String(k)) continue } // 如果这里是对象的话 transform(res, value, String(k)) } } transform(res, obj, '') console.log(res) function arrHelper(res, arr, str) { // console.log('str'+str) for(let i = 0;i < arr.length;i++) { if(typeof arr[i] !== 'object') { res[str+'['+i+']'] = arr[i] continue } transform(res, arr[i], str+'['+i+']') } } 写了一套笨方法。。。