s24344,
однотипные вопросы пишите в одной теме ...
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
</style>
</head>
<body>
<ul class="list"></ul>
<script>
function fn(arr) {
let obj = arr.reduce(function(obj, {country}) {
obj[country] = (obj[country]||0) + 1;
return obj;
}, {});
return Object.keys(obj).sort((a,b) => obj[b] - obj[a] ||( a > b ? 1 : -1)).map((country, i)=>({id : ++i, country}))
};
const arr = [
{ id: 1, name: 'Alexey', country: 'Moscow' },
{ id: 2, name: 'Mikhail', country: 'Tula' },
{ id: 3, name: 'Vladimir', country: 'Moscow' },
{ id: 4, name: 'Andrey', country: 'Vladivostok' },
{ id: 5, name: 'Andrey', country: 'Moscow' },
{ id: 6, name: 'Peter', country: 'Vladivostok' },
{ id: 7, name: 'Sergey', country: 'Tula' }
]
,
arrFilter = fn(arr),
html = arrFilter.reduce(function(html, el) {
return html += '<li class="item" ><div>' + el.id + ' ' +el.country+'</div></li>'
},"");
document.querySelector(".list").innerHTML = html;
</script>
</body>
</html>