let keyMap = { 'ids': 'id', // key转换 }; for (let i = 0; i < list.length; i++) { let arr = list[i]; for (let arrKey in arr) { if (arr.hasOwnProperty(arrKey)) { let newKey = keyMap[arrKey]; if (newKey) { arr[newKey] = arr[arrKey]; delete arr[arrKey]; } } } } list.forEach(item => { item['name'] = 'ly'; // 像数组插入id字段 });
最新评论