javascript - Lodash uniqBy multiple for array? - Stack Overflow

I have array:[ [ '245', '0', '0.0100', '245,0,0.01' ],[ '2

I have array:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
  [ '245', '1', '0.0100', '245,1,0.01' ],
  [ '208', '0', '0.0300', '208,0,0.03' ],
  [ '208', '0', '0.0500', '208,0,0.05' ],
  [ '208', '0', '0.0600', '208,0,0.06' ] ]

and i need to get unique arrays by [0] and [1] cells like this:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
  [ '245', '1', '0.0100', '245,1,0.01' ],
  [ '208', '0', '0.0600', '208,0,0.06' ] ]

Help please/

I have array:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
  [ '245', '1', '0.0100', '245,1,0.01' ],
  [ '208', '0', '0.0300', '208,0,0.03' ],
  [ '208', '0', '0.0500', '208,0,0.05' ],
  [ '208', '0', '0.0600', '208,0,0.06' ] ]

and i need to get unique arrays by [0] and [1] cells like this:

[ [ '245', '0', '0.0100', '245,0,0.01' ],
  [ '245', '1', '0.0100', '245,1,0.01' ],
  [ '208', '0', '0.0600', '208,0,0.06' ] ]

Help please/

Share Improve this question edited May 23, 2016 at 14:52 Pranav C Balan 115k25 gold badges171 silver badges195 bronze badges asked May 23, 2016 at 14:43 axonaxon 1092 silver badges11 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Use lodhash uniqBy() method

var data = [
  ['245', '0', '0.0100', '245,0,0.01'],
  ['245', '1', '0.0100', '245,1,0.01'],
  ['208', '0', '0.0300', '208,0,0.03'],
  ['208', '0', '0.0500', '208,0,0.05'],
  ['208', '0', '0.0600', '208,0,0.06']
];

console.log(
  _.uniqBy(data, function(v) {
    return v[0] + ' ' + v[1];
  })
)
<script src="https://cdnjs.cloudflare./ajax/libs/lodash.js/4.13.0/lodash.js"></script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744241064a4564706.html

相关推荐

  • javascript - Lodash uniqBy multiple for array? - Stack Overflow

    I have array:[ [ '245', '0', '0.0100', '245,0,0.01' ],[ '2

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信