Linked Questions
20 questions linked to/from How do I check if an object has a key in JavaScript?
1904 votes
33 answers
1.5m views
How do I check if an object has a specific property in JavaScript?
How do I check if an object has a specific property in JavaScript? Consider: x = {'key': 1}; if ( x.hasOwnProperty('key') ) { //Do this } Is there another way to do it?
2 votes
1 answer
1k views
JS Check property exists for number values [duplicate]
I have used like below example to check property exists on an object. const payload ={payment:0} if(payload && payload.payment){ console.log(payload.payment) }else{ console.log('Issue') }...
0 votes
1 answer
191 views
ReactJS: Check if values of array is inside object [duplicate]
I have an object like this: let column = ["A", "B", "C", "D"] validation: { type: ... id: ... // and possible report that could exists or not ...
0 votes
0 answers
74 views
How to iterate through an array of objects with checking the key of iteratees with the state? [duplicate]
Variable br must consist only of bool values. Which have been gotten by looping through the first array. state ={ nonRelated: this.props.non_related.value, 1:true, 2:true, 3:false, ...
49 votes
9 answers
169k views
Check if property exists using React.js
I'm new to using react.js, and am trying to write a re-usable component that has an optional property passed to it. In the component, that optional property pulls data from a db using meteor, then I ...
49 votes
1 answer
31k views
Object.hasOwn() vs Object.prototype.hasOwnProperty()
The new method Object.hasOwn() returns a boolean indicating whether the specified object has the indicated property as its own property but so does Object.prototype.hasOwnProperty(), what is the ...
20 votes
3 answers
6k views
Why does mongoose model's hasOwnProperty return false when property does exist?
I have this code : user.findOne( { 'email' : email }, function( err, User ) { if ( err ) { return done(err); } ...
13 votes
2 answers
8k views
Equivalent of Python's KeyError exception in JavaScript?
I am trying to access a certain member in a JavaScript object. In order to do this, I need to try out a couple of key values. For example, Object['text/html'] which will give me an export link for a ...
2 votes
3 answers
12k views
Filter an array of objects according to the name of the key in the objects [duplicate]
I have an array of objects that I want to filter based on the name of the key for those objects. In this particular case I know that there will be one key/value pair for each element in the array. ...
3 votes
4 answers
15k views
How do I get the value of a key from a list of objects in Javascript?
I have a list of objects in the following way: obj = [ { a:[1,2,3] }, { b:[4,5,6] }, { c:[7,8,9] } ] How do I get the correspoding array for a key using javascript? Eg. For b, I would get [4,5,6]. I ...
3 votes
2 answers
3k views
How to check if a key is exists in JSON Array of Objects
I am having the JSON array of objects like below, let data = [ { "node":[ { "name":"aaaaa", "count":"2", } ] ...
0 votes
1 answer
2k views
Parsing JSON array of objects: undefined property
So, similar to my my previous question here (I was unsure whether to make a new question or edit the old one), I managed to sucessfully parse the body JSON response using the code seen below. However ...
-1 votes
1 answer
2k views
Dictionary .has("key") not working, must use dictionary["key"] != "undefined" instead [closed]
(Using javascript) I've seen some answers saying dictionary.has("key") will evaluate to true or false based on if the key is in the dictionary. For some reason, this hasn't worked for me at ...
0 votes
2 answers
1k views
check if property exist inside List of objects
I have list of objects response.tasks: {userLastName: ', srCreationDate: '', idNumber: '', firstName: ', insStartDate: null, …} and I want to know if I have some properties for userLastName it will be ...
-2 votes
2 answers
1k views
Write a function that takes a user object and returns the value of the password key
New learner here, I'm stuck on a practice question for a course and I'm not sure what it's asking me to do here. The problem is as follows: Write a function that takes a user object, which represents ...