对象按要求填充数组

某公司 1 到 12 月份的销售额存在一个对象里面 如下:{1:222, 2:123, 5:888},请把数据处理为如下结构:[222, 123, null, null, 888, null, null, null, null, null, null, null]

const obj = { 1: 222, 2: 123, 5: 888 };
const arr=Array.from({length:12},(_el,index)=>obj[index+1]||null)
const arr2=Array.from({length:12}).map((_el,index)=>obj[index+1]||null)
贡献者: huxiguo