Ok i think i have managed to do what i need. But im having issues saving the data. @ahmadnasriya could you take a look where is mistake here? And maybe i did in a very complicated way and there is a easier/shorter way to do it?
But it works
Console shows correct results.
let newestpoints = $w("#newpoints").value;
$w('#dataset2').onReady(() => {
console.log("Finding TOP5 points...")
wixData.query('POINTS-PERSONAL')
.eq('title', player)
.find()
.then((result) => {
const entries = result.items[0];
// Loop through all the items to find the highest ones
let playerpoints = entries
let points = [];
points.push(playerpoints.points1, playerpoints.points2, playerpoints.points3, playerpoints.points4, playerpoints.points5, Number(newestpoints));
// Sort points as descending order
points.sort(function (a, b) {
return b - a;
})
let points11 = 0;
for (let i = 0; i < 1; i++) {
points11 += points[i];
}
let points22 = 0;
for (let i = 1; i < 2; i++) {
points22 += points[i];
}
let points33 = 0;
for (let i = 2; i < 3; i++) {
points33 += points[i];
}
let points44 = 0;
for (let i = 3; i < 4; i++) {
points44 += points[i];
}
let points55 = 0;
for (let i = 4; i < 5; i++) {
points55 += points[i];
}
// Get only the highest 5 points;
console.log ("Points 1 is:", points11)
console.log ("Points 2 is:", points22)
console.log ("Points 3 is:", points33)
console.log ("Points 4 is:", points44)
console.log ("Points 5 is:", points55)
let toInsert = {
"points1": points11,
"points2": points22,
"points3": points33,
"points4": points44,
"points5": points55
};
wixData.save("POINTS-PERSONAL", toInsert )
})
.then((item) => {