I have a simple question but still haven't found neither figured out out to solve this.
I have this array:
var charsAndTypes = [
{'type': 'Power', 'characters': ['Bunny','Buffalo']},
{'type': 'Magic', 'characters': ['Sheep','Dragon']},
{'type': 'Sense', 'characters': ['Fox','Lion']},
{'type': 'Charm', 'characters': ['Cat','Raccoon']}
];
I need to search for the "characters", like "Bunny", and then catch the "type" to save it to a var, tried .map(), .filter, foreach inArray, but stil didn't work has I wanted
Basicly I need a function like this in the end
function searchInArray ( array, string ){
//search in characters what array contains that string
//then return the array that has the value
}
var charType = searchInArray(charsAndTypes, "Bunny");
//then the output must be "Power" in this case
console.log(charType.type);