Quantcast
Channel: Help! with 2.0 - Twine Forum
Viewing all articles
Browse latest Browse all 1844

Sorting objects inside an array by a specific property

$
0
0
As the title says, I have an array that contains multiple objects. The objects are all similar, with the same properties but with different values for each - for example, they all have a "Name", but the string of that property is different for each object. How would I go about sorting the objects in the array by a given property?

I'm guessing it will take a more specific form of the array.sort() method, which I believe would work in that form if the array contained variables rather than objects. If relevant, I'd need one method for sorting text strings alphabetically, and another for sorting numbers in ascending/descending order.

As a side note, if two different objects were to have the same value for the property they are being sorted by - if the "Name" for each was "Kevin", for example - how would this method sort those two objects?

I am using SugarCube 2.7.2 on Twine 2.0.11

Viewing all articles
Browse latest Browse all 1844

Trending Articles