My JSON.stringify return empty object notation "{}" for an object that seems to have properties?
And hasOwnProperty returns false But The object that seems to have properties?
This is my properties
My JSON.stringify code:-
const locals =JSON.stringify(action.data.displayNameLocalization);
console.log( locals);
If my object have properties,hasOwnProperty() return false.
const test=action.data.displayNameLocalization;
console.log(test);
console.log(test.hasOwnProperty());
Result:-
I have no idea what is happening...? Anyone can help men with this..?
The hasOwnProperty() method returns a boolean indicating whether the object has the specified property as its own property (as opposed to inheriting it) so you should pass a property name when using this function.
Note, that you can use the new Object.hasOwn() static method which returns true or false indicating if the specified object has the indicated property as its own property (yet it is still not supported by all browsers)
const test = {ch : 'China', fr: 'Franch'};
console.log(test.hasOwnProperty('ch')); // checking if the property `ch` is an own property
console.log(test.hasOwnProperty()); // checking for undefined..
console.log(Object.hasOwn(test, 'ch')); // using the new Object.hasOwn method
More about hasOwnProperty - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty