So I have an array of objects that look like this:
[
{
Other: 23,
},
{
Choco: 21,
},
{
Vanila: 10,
},
{
"Other - WA": 2,
},
{
Strawbery: 30,
},
];
What needs to be done is I have to sort this by showing :
- All that have keys 'Other'.
- The rest starting from most to least by value.
I figured I could create 2 separate arrays by moving all that have key 'Other' there and the rest in a separate one. Then I simply sort by value and then join the 2 arrays using spread operator. The problem is I can't get it to detect 'Other' in the key and when it does it does it literally not like how 'LIKE' from SQL would do here's the code for now:
let other = pgData.contents[6]?.locCounts?.filter((loc) =>
Object.keys(loc).includes("Other")
);
It only returns key with "Other" not "Other - WA" like I want to get everything that has the word "Other" in it regardless of whats in front of it.
Object.keysjust to figure out the name, and prohibiting other properties from being added. I recommend a structure like{name: "Other", price: 23}or something like that, then you'll find it much less awkward to work with going forward.Object.keys(el)[0]/Object.values(el)[0]every time you use the array when you could be doing the much more intuitiveel.name/el.price(or whatever the k/v pair represents--hard to know under the current format).[0]it.