node.js - How to check value existence as hasOwnProperty JSON NodeJs -


i've found how check key in json object :

var myjson = {'key':'value', 'key2':'value2'}; if(myjson.hasownproperty('key2')){      //do if key exist } 

now, how can check value2 exist ? hasownvalue exists ?

as molda suggests, there no way find out whether object contains value, other looping on fields.

pure js

var myobject = {"a": 1, "b": 2}; var valueimlookingfor = 2;  (var key in myobject) {     if (myobject[key] === valueimlookingfor) {         console.log('yay, myobject contains', valueimlookingfor);     } } 

there libraries kind of stuff though. using lodash' includes() becomes easy:

_.includes(myobject, valueimlookingfor); // true 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -