There is such a "script" that filters the list by clicking on the letter of the alphabet.
$('.AlphabetNav a').click(function(evt) { evt.preventDefault(); var $navItem = $(this), $contacts = $('.Contact'); $contacts.show(); if ($navItem.hasClass('active')) { $navItem.removeClass('active'); } else { $('.AlphabetNav a').removeClass('active'); $navItem.addClass('active'); $.each($contacts, function(key, contact) { var $contact = $(contact), $contactName = $contact.find('.Contact-name'), $nameArr = $contactName.text().split(' '); console.log($nameArr[0].split('')[0].toLowerCase()); if ($nameArr[0].split('')[0].toLowerCase() !== $navItem.text().toLowerCase()) { $contact.hide(); } }); } }); I want to do it in pure JavaScript, but with some changes. JSON comes from the server in different languages, so the list of alphabetic letters can also be different, respectively. What is the script creation algorithm?
sortarray (items)sortth alphabetically.We take
items.values().chartAt[0], loop through all the elements of the array and, ifchartAt[0]indexOfin the new array, then skip.I do not know further.