underscore.js 数组拆分

发布于 2022-09-01 19:51:17 字数 1061 浏览 27 评论 0

//原数组

[
      {n:"jerry",a:"static/images/liuyan.jpg",from:"1", to: "10",msg:"在吗555",date:"2010-12-23"},
       {n:"jerry",a:"static/images/liuyan.jpg",from:"1", to: "10",msg:"回来了吗",date:"2019-12-23"}
      {n:"刘云",a:"static/images/ly.jpg",from:"10", to: "1",msg:"回来了:)",date:"2019-12-3"},
       {n:"刘云",a:"static/images/ly.jpg",from:"10", to: "1",msg:"给你带了东西",date:"2019-12-23"},
       {n:"刘云",a:"static/images/ly.jpg",from:'10', to: "1",msg:"累死了",date:"2012-1-1"}
 ]

拆分为这个样子

[ 


  [
      {n:"jerry",a:"static/images/liuyan.jpg",from:"1", to: "10",msg:"在吗555",date:"2010-12-23"},
       {n:"jerry",a:"static/images/liuyan.jpg",from:"1", to: "10",msg:"回来了吗",date:"2019-12-23"}
  ],


  [
      {n:"刘云",a:"static/images/ly.jpg",from:"10", to: "1",msg:"回来了:)",date:"2019-12-3"},
       {n:"刘云",a:"static/images/ly.jpg",from:"10", to: "1",msg:"给你带了东西",date:"2019-12-23"},
       {n:"刘云",a:"static/images/ly.jpg",from:'10', to: "1",msg:"累死了",date:"2012-1-1"}
  ],


]

如何用 underscore 实现

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北城挽邺 2022-09-08 19:51:17

groupBy

峩卟喜欢 2022-09-08 19:51:17

为什么要用underscore呢?用原生写也很好实现吧。
1.循环得出唯一的人名数组
2.循环原数组,同名就push进去
3.重新组合

小兔几 2022-09-08 19:51:17

@小_秦 你真牛逼,看文档的学习能力太强了,羡慕:)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文