How can I check if an object has a certain property in AngularJS?
There are multiple methods available to check if an array contains duplicate values in JavaScript. You can use the indexOf() method, the Set object, or iteration to identify repeated items in an array.
We can check if a property exists in the object by checking if property !== undefined . In this example, it would return true because the name property does exist in the developer object.
You could use 'hasOwnProperty' to check if object have the specific property.
if($scope.test.hasOwnProperty('bye')){ // do this }else{ // do this then }
Here's a demo in jsFiddle.
Hope this helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With