[Solved] Random JSON where x is true


If you want to find the first match, use find(), if you want to find a random one, you could use filter() and then access a random element:

let arr = [{"id":1,"dex":1,"form":"null","mon":"Bulbasaur","type1":"Grass","type2":"Poison","egg-group-1":"Monster","egg-group-2":"Grass","legend":"FALSE","gen":1},{"id":2,"dex":2,"form":"null","mon":"Ivysaur","type1":"Grass","type2":"Poison","egg-group-1":"Monster","egg-group-2":"Grass","legend":"FALSE","gen":1}];

let first = arr.find(v => v['egg-group-1'] === 'Monster'); // will return the first one
console.log(first);

let random = arr.filter(v => v['egg-group-1'] === 'Monster');
console.log(random[Math.floor(Math.random()*random.length)]);

8

solved Random JSON where x is true