Underscore.js - get unique property values

后端 未结 5 1976
我寻月下人不归
我寻月下人不归 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

    • Use flatten first, to convert the nested array to a flat array.
    • Then pluck to get the "name" values as an array
    • Finally uniq

    _.uniq(_.pluck(_.flatten(items), "name"))
    

    Fiddle

提交回复
热议问题