Loading... **对象转数组** <div class="tip inlineBlock share simple"> ``` let arr = [] let obj = { dr: "dr001", ljy: "ljy002" } for(let prop in obj) { arr.push({ name: prop, ct: obj[prop] }) } console.log('arr', JSON.stringify(arr, null, 2)); ``` </div> **数组转对象** <div class="tip inlineBlock share simple"> ``` let arr = [ { name: 'dr', ct: 'dr001' }, { name: 'ljy', ct: 'ljy002' } ] let obj = {} arr.forEach(item=> { obj[item.name] = item.ct }) console.log('obj', JSON.stringify(obj, null, 2)); ``` </div> Last modification:September 2, 2023 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 如果觉得我的文章对你有用,请随意赞赏
One comment
⌇●﹏●⌇