sortBy doesn't work

Hello! I cant understand. It seems that i do all right…but it doesn’t work. The items gets from the table like they are written there.

var dataQuery = {
condition: "id_user = '"+code+"'",
sortBy: ["nameProduct DESC"]
};
var products = Backendless.Persistence.of(Products).find(dataQuery);
for(var i = 0; i < products.data.length; i++) {
console.log("Product name = " + products.data.nameProduct); // here i check And see that it doesnt work
}

Hi Valeria,

have you tried to log in console

"Product name = " + products.data[і].nameProduct

The product.datait is an array and the array elements should be referred to by index.

UPD
Sorry, for some reason our text editor misses ‘[і]’ and convert it to tag. The solution is to use next signature:

var query = new Backendless.DataQuery();

query.options = {
 sortBy: ["nameProduct DESC"]
};
query.condition = "id_user = '"+code+"'";

Regards,
Stanislav

THANK YOU, Stanislav !! All is working =)

Regards,
Valeria

You’re welcome :slight_smile: