Below, I have an array that looks like JSON data. I get this result by querying something and pushing it to var test = [];. The way I append the strings and numbers into my test array is by running test.push({item_name: name, number_of_items: number});. Just to be clear, it is not JSON:
[{"item_name":"Peri Peri Chicken","number_of_items":6},{"item_name":"Deep fried beef","number_of_items":22},{"item_name":"Roast chicken","number_of_items":7},{"item_name":"Chow Mein","number_of_items":3},{"item_name":"Sweet and sour noodles","number_of_items":5},{"item_name":"Steak","number_of_items":32}]
Now, I want to sort the array so that it shows the array from the largest number_of_items to the smallest number_of_items.
I have tried to sort it like you would do with a JSON array, but it doesn't work as I have realised that I cannot access the elements in that array by using test.number_of_items. I tried THIS method to sort the array, but it doesn't work for me as my data is not in JSON.
It would also really helpful if someone can tell me if there's a better way to append multiple data into the same index of an array, and also to be able to access the elements easier in the future? so for example, on index 1 I would have something like (elem1: string1, elem2: number1) and then index 2 (elem1: string2, elem2: number2) and ...
