I need a way to get the title/name of an array, just by detecting the values inside of that array in Javascript.
I have an json array where there are the arrays of greeting and food. The variable x is equal to hi and the variable y is equal to pizza.
var $arrays = {greeting: ['hello', 'hi'], food: ['pizza', 'cookie']};
var x = 'hi',
y = 'pizza';
I need to now return the name of greeting for x, and the name of food for y.
if(x=='hi') {
alert($array.greeting); // alert('greeting');
}
if(y=='pizza') {
alert($array.food); // alert('food');
}
In which way would this work better, in Javascript or jQuery, how so?