Hi Mantas,
If you got it right, you want to retrieve the highest points of all player entries, while keeping in mind that each entry has 6 points.
If that’s the case, then …
// A constant to store the points;
const points = [];
wixData.query('POINTS').eq('player', 'Ahmad').limit(1000).find().then((result) => {
const entries = result.items;
// Loop through all the items to find the highest ones
entries.forEach(entry => {
// Loop through the points of each entry
for (let i = 1; i <=5; i++) {
// Add the point to the points array
points.push(entry[`points${i}`]);
}
});
/* Now that we have each and every single point of that player
we just need to sort the array, then get the highest 5 points */
entries.sort((a, b) => {
return b - a;
});
// Get only the highest 5 points;
const pointsNum = 5; // Number of points to get.
const highest_points = points.slice(0, pointsNum);
})
Once you have the highest points of all entries, you can do whatever you want with them, display, store, or just print them to the console, simple, isn’t it?
Hope this helps~!
Ahmad