Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  32] [ 6]  / answers: 1 / hits: 15703  / 11 Years ago, tue, february 4, 2014, 12:00:00

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:



[
[{
name: Type 2,
id: 14
}],
[{
name: Type 1,
id: 13
}, {
name: Type 3,
id: 15
}],
[{
name: Type 2,
id: 14
}],
[{
name: Type 1,
id: 13
}]
]


to this:



[Type 1,Type 2,Type 3]


i.e. no duplicated and name property only.



Any suggestions much appreciated.


More From » json

 Answers
2
_(data).chain().flatten().pluck('name').unique().value()


(Convert the nested lists to a flat one, pick name from each of the objects in the list, and make it unique.)


[#72729] Monday, February 3, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;