Answer the question
In order to leave comments, you need to log in
How to sort the elements of a list?
Good day.
There is a code:
const breachPreviewList = document.querySelector('.breach-preview-list');
breaches.forEach((breach) => {
let li = document.createElement('li'),
p1 = document.createElement('p'),
p2 = document.createElement('p'),
...
p1.innerHTML = `${breach.option1}`;
p2.innerHTML = `${breach.option2}`;
....
li.dataset.sort = `${breach.tierNum}`;
li.appendChild(p1);
li.appendChild(p2);
...
breachPreviewList.appendChild(li);
});
Answer the question
In order to leave comments, you need to log in
In fact, it's easier to sort breaches first, and then create a list from it
breaches
.sort((a, b) => a.tierNum - b.tierNum)
.forEach(...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question