我有一个包含 12 个条目的数组。我喜欢按标题对它们进行排序。许多文章都有相同的标题,我可以很容易,因为标题是相同的。最后我可能是 3 或 4 组。
我有非常小的 javascript 代码,因为我不知道我是否想用循环或其他方式来做。
Javascript
var totalGroups = [];
var actualGroup = [];
var contentarticles = articles.contentarticles,
article,
$out = $("#articlesOutput");
for (var i = 0; i < contentarticles.length; i++) {
if (!article || article.title != contentarticles[i].title) {
article = contentarticles[i];
document.getElementById('articleForNaviTopTitle').innerHTML = article.title;
document.getElementById('articleForNaviTopID').innerHTML = article.id;
var articlesOutput = [
'<li><a href="./certifiedTraining/id=', article.id, '/step=', i + 1, '">',
article.title,
'</li>'
].join("");
$out.append(articlesOutput);
}
}
// till this point all works fine, and a code above gives results in the image below.
//**Im struggeling right there, how to sort this array by groups?????**
while (article.title(this) == article.title(next))
{
code block to be executed
}