As far as I know jQuery has a function inArrary which is apply like the following
$.inArray(value, array); it return -1 if not in array
However, this function only apply to value and is not suitable for the multidimension array
eg . fruit [ apple,orange]
For instance, if I have an array like this
eg. fruit [apple => [red,$1], orange => [orange,$5]]
I have to check whether a value exist (eg. banana) as the array key, are there any function appropriate in this case?
Arrays cannot have string keys in JavaScript. Only objects can.
If you want to see if an object contains has a key
banana, you can simply test that it isn’tundefined:… or use
hasOwnProperty, which may be better in cases when you may have initialized a property toundefined: