Underscore.js - get unique property values

后端 未结 5 1996
我寻月下人不归
我寻月下人不归 2021-02-13 18:12

I only recently discovered the power of underscore.js, still new to the methods I kindly ask for a suggestion:

How do I get from this:

[
    [{
                 


        
5条回答
  •  春和景丽
    2021-02-13 18:24

    Simple way:

    1. use _.map to get all the names

    var names = _.map(items, function(item) { return item.name});

    2. Get the _.uniq from that names

    var uniqueNames = _.uniq(names);

提交回复
热议问题