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)
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.
Alternatively, but not recommended, you could change its prototype to act more like a standard object...
data.__proto__ = Object.prototype;
This hack works for me:
req.body = JSON.parse(JSON.stringify(req.body));