Questions tagged [hasownproperty]

hasOwnProperty is a method of the object object in JavaScript. It is used to check whether the calling object has the specified key as a direct member. It does not traverse the prototype chain.

hasOwnProperty is a method of most objects. A notable exception is the window object in IE.

116 questions
0
votes
1 answer

Flex 4.6 hasOwnProperty not working

I upgraded my project from Flex 4.0 to Flex 4.6 and everything seemed to work no major errors. But all of a sudden: I get TypeError: Error #1009: Cannot access a property or method of a null object reference. when using hasOwnProperty on code…
Craig Mc
  • 505
  • 1
  • 13
  • 30
0
votes
1 answer

Object.hasOwn and hasOwnProperty doesn't narrow TypeScript type as expected

I have a simple object type in TypeScript and an object made of all the keys in this object but not of the same type. I'm expected hasOwnProperty or hasOwn to narrow the type to the type keys but it isn't. Here is a small example that summarize the…
yotamN
  • 711
  • 2
  • 9
  • 22
0
votes
2 answers

Recursive hasOwnProperty for objects

I have an object as: const object = {}; object.property1 = 54; object.property1.property1 = 60; now I would like to achieve something like this: if(object.hasOwnProperty('property1')){ //do something } else…
user16570636
0
votes
1 answer

Getting Own object keys with no built-in methods

There is a task/challenge to get all object keys as an array. The issue is all build-in arrays and object methods are restricted ( no Object.keys() ). I can use for in loop function getKeys(obj) { const keysArr = []; for (const key in obj) { …
Ramon
  • 1
  • 1
0
votes
0 answers

I am trying to push a value to an array only if the array exists within a javascript object. If the array doesn't exist, I wish to create one and add

I have been following a JavaScript course (freeCodeCamp) on Youtube Timestamp:02:03:06. Before following up with their solution I made my own attempt. In the project, I am supposed to create a function updateRecords that adds information to the…
0
votes
0 answers

What is the issue with having duplicated variables accross instances of objects?

In the following example, the Bird constructor defines two properties: name and numLegs: function Bird(name) { this.name = name; this.numLegs = 2; } let duck = new Bird("Donald"); let canary = new Bird("Tweety"); name and numLegs are called…
0
votes
3 answers

hasOwnProperty() is only checking if a certain property exists in a JSON, but doesn't return anything if it doesn't

I keep trying different methods to check if this JSON contains "attributes." In this way I can determine if the given coordinates are outside of wetlands. If they are in wetlands, "attributes" will exist in the JSON. If they aren't in wetlands,…
Jack
  • 53
  • 8
0
votes
2 answers

Avoid recurring 'if' verification to check if an object has property

I do know how to check if a property exists (hasOwnProperty, in, !== undefined, etc). But I don't know how to avoid to perform an action on this property if it doesn't exist. Is there a solution to avoid the if (property && action in my case)…
0
votes
1 answer

Highchart React not rendering heat map after refresh its throwing error

Import statement for high charts : // Import Highcharts import Highcharts from 'highcharts'; import HighchartsReact from "highcharts-react-official"; import HighchartsHeatmap from 'highcharts/modules/heatmap'; // Load Highmaps as a module …
0
votes
2 answers

Is !obj[key] a good practice to check the existence of an object's property in JavaScript?

Every now and then, I see this pattern: if (!obj[key]) { // key does not exist inside object obj[key] = ... } else { // maybe do something else with obj[key] } but I find it extremely wrong. What if actually obj[key] has the value false…
but-why
  • 533
  • 3
  • 10
0
votes
1 answer

Javascript HasOwnProperty Polyfill

I know this may sound like an absurd, unnecessary question, but it really isn't. https://caniuse.com/?search=Hasownproperty shows 100% of tracked desktop clients support, which is as you would expect. But switching to tracked mobile clients shows a…
Kithraya
  • 358
  • 2
  • 10
0
votes
2 answers

Call 'hasOwnProperty' on a reponse (fetch-api)

I know this is kinda dumb/useless, but I would love to understand it. I tried to call hasOwnProperty on a response-object but it always returns false. Why? (await fetch('http://dummy.restapiexample.com/api/v1/employees')).hasOwnProperty('status');
faragos
  • 18
  • 3
0
votes
1 answer

Why performance.hasOwnProperty('getEntries') returns false while typeof performance.getEntries returns function?

Window property performance has a function call getEntries to retrieve all performance entries. which works on all modern browsers but doesn't work on a few older browsers like Safari 10. To add a check of working browsers.... If we try to verify…
YASH DAVE
  • 1,066
  • 12
  • 25
0
votes
1 answer

Node JS - Check if JSON File hasOwnProperty with nested elements

im simply trying to check if a JSON Object has a specific key. First i parse the JSON File to an object but when i try this: console.log("Inspect:" + util.inspect(oldConfig[websiteName][groupName])); console.log("Check Prop: " +…
0
votes
2 answers

document.hasOwnProperty("hidden") returns false but document has the property hidden

I'm trying to check if document has 'hidden' property using document.hasOwnProperty but it always returns false in Chrome (74). I've tried Object.prototype.hasOwnProperty but that too returns false. When I tried to stringify and parse back document…
shrys
  • 5,860
  • 2
  • 21
  • 36