Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  97] [ 6]  / answers: 1 / hits: 22056  / 11 Years ago, thu, may 16, 2013, 12:00:00

Not sure why hasOwnProperty() seems to be missing from my object...



I'm getting data from an http post in expressjs3, like this:



someControllerFunction: function(req, res){
var data = req.body.loc;
...
}


However if I do:



data.hasOwnProperty('test'); 


I get:



Object object has no method 'hasOwnProperty' 


Perhaps I'm missing something obvious, but what?



(Node 10.5, Express 3.2.1)


More From » node.js

 Answers
3

The object may not have Object.prototype as its prototype.



This is the case if the object was created with...



var data = Object.create(null);


You could use...



Object.prototype.hasOwnProperty.call(data, 'test');


...to test if the property exists.


[#78200] Wednesday, May 15, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jayla

Total Points: 14
Total Questions: 96
Total Answers: 123

Location: Greenland
Member since Fri, Jul 31, 2020
4 Years ago
jayla questions
;