You can use Object.entries()
to convert the object into Array of objects.(您可以使用Object.entries()
将对象转换为对象数组。)
const src = { '1': 'House', '2': 'Town Home', '3': 'Apartment' }; const dist = Object.entries(src).map(([id, name]) => ({ id, name })); console.log(dist);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…