Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

js数据转换问题

image.png
上面这种数据类型怎么转换成下面这种,在线求答案
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
function convertList(list) {
  const result = []
  list.forEach(item => {
    let o = result.find(r => r.month === item.month)
    if (o) {
      o.list.push(item)
    } else {
      result.push({ month: item.month, list: [item] })
    }
  })
  return result
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...