I am fetching data from a JSON file and rendering it to a table, but I need to sort it by ratings and votes with select options I've tried different ways but none of them worked.
This is a link to my code: https://jsfiddle.net/natefr0st/596ew8zc/5/
I've tried to get the ratings with querySelectorAll and loop through each rating and then sort it but it didn't work, tried other different methods and again without result
const sortMenu = document.getElementById('sort');
sortMenu.addEventListener('change', sortTable);
function sortTable() {
const rating = document.querySelectorAll('.rating')
// rating.forEach((val, i) => console.log(val.innerHTML));
// function compare(a, b) {
// return a.imdb_rating > b.imdb_rating ? 1 : -1;
// }
if(sortMenu.value == 1) {
rating.forEach(function(val, index) {
let ratingArr = Array.from(val.innerHTML);
return ratingArr.sort();
});
}
}