Is there any not loop-based approach in JavaScript or JQuery that can check presence of some VALUE from object’s properties. I mean here if I have
obj = { prop1:val, prop2:val2 }
is that possible with maybe one statement check is val2 presence among values of obj ?
UPDATE 1: The loop here is not the key! I can use loop if it is wrapped in some JQuery predefined function!
UPDATE 2:
Writing a hand-made function is not so elegant, I think. I would like to find some library based solution for such a common and usual problem.
No you cannot find if a value exist in an object in one statement without looping.
You can use native API or a library.. but they are going to internally loop thru all values.
The toll on any other method will be same as iterating the object.. So I would write a simple
forloop to do it.I would simply write this 4 line code in my script file and include that script file instead of including a library.. which would be the same. http://jsfiddle.net/sQW4P/2/ <– Incase if you need such a function.