Let's say you have JSON like the following:
[{
"Rarity": "Common",
"EffectOne": "+4 ACC",
"EffectTwo": "-1 SPD",
"EffectThree": "",
},
{
"Rarity": "Common",
"EffectOne": "+4 ACC",
"EffectTwo": "-1 SPD",
"EffectThree": "",
},
{
"Rarity": "Rare",
"EffectOne": "+4 ACC",
"EffectTwo": "-1 SPD",
"EffectThree": "",
}]
How can you target the objects that have a shared value for one of the Properties, such as "Rarity": "Common".
Can you do (for the sake of this example, let's say this JSON is just named data): data.rarity.common? or would it be data.rarity("Common"). The reason I ask is I actually can't seem to find this info anywhere in JSON jquery documentation and I would like to populate data in different places based on specific values.
"Rarity": "Common", you have a few options, primarilydata = data.filter(x => x.Rarity == "Common");An Exampledata.is because data is an array. It does not have properties, but rather indexes. Thefilterfunction I've provided simply iterates through each item (asx), and evaluates the condition supplied (x.Rarity == "Common"). If the result isfalse, the item is removed from the array.