Answer the question
In order to leave comments, you need to log in
How to concatenate unique values in an array of objects?
Trying to make a mixin in PUG
- var data =
[
{
"title": "Артем"
},
{
"title": "Аня"
},
{
"title": "Виталик"
},
{
"title": "Гена"
},
{
"title": "Дима"
},
{
"title": "Вася"
},
{
"title": "Гриша"
},
{
"title": "Андрей"
}
]
mixin sort(data)
- var sort = data.sort(function(a, b) {return a.title.localeCompare(b.title);}); // сортируем по алфавиту
each item in sort
.div= title.charAt(0)
А
А
А
В
В
Г
Г
Д
Answer the question
In order to leave comments, you need to log in
- var data = [ { "title": "Артем" }, { "title": "Аня" }, { "title": "Виталик" }, { "title": "Гена" }, { "title": "Дима" }, { "title": "Вася" }, { "title": "Гриша" }, { "title": "Андрей" } ]
mixin sort(data)
- var grouped = data.reduce((acc, n) => {
- var name = n.title[0];
- acc[name] = acc[name] || [];
- acc[name].push(n);
- return acc;
- }, {});
each group, name in grouped
div
h3= name
each obj in group
div= obj.title
div
+sort(data)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question