Having one only key/value into an object, how to get them without know the key name? (If it’s possible)
var m = {x:5}; // we don't know x is the key
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
hasOwnPropertyfor things like thishttps://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/HasOwnProperty
So using this knowledge, you can write a function that basically checks whether a given key exists in an object: