Вывести random без повторений
Помогите сделать random без повторений
for (var i = 0; i < response.items.length; i++) {
var text = new String('');
for (var c = 0; c < 5; c++) {
let random = Math.floor(Math.random() * response.items[i].listTagDto.length)
text = text + "<a href=\"#\" class=\"tag\"> " + response.items[i].listTagDto[random].name + " </a>"
}
Ответы (1 шт):
Автор решения: Igor
→ Ссылка
var shuffledNames = response.items[i].listTagDto.map(i => i.name).sort(() => Math.random() - 0.5);
var text = shuffledNames.map(i => `<a href="#" class="tag"> ${i} </a>`).join('');