How can I make a function that outputs only 3 frequently used usernames from an object
let allUser = await User.findAll()
var result = {};
allUser.forEach(function(v){
result[v.age = result[v.age] + 1 || 1;
})
for (var key in result)
console.log(key + result[key])
console.log('amount ' + key + ' == ' + result[key] + ' times <br>')
//amount 19 == 1 times
//amount 15 == 1 times
//amount 20 == 34 times
I don't have 3 but all at once, I want it to sort But not more than 3.
1. 34
2. 1
3. 1
Aucun commentaire:
Enregistrer un commentaire