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 badges1 Answer
Reset to default 8Use 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
评论列表(0条)