I have an array of JSON strings. Consider the first element of the array has 4 attributes, {a:name,b:address,c:dob,d:country},
and the second element has only 3 attributes, it has no 'c' attribute. when iterating through the array, if the attribute is not present, i should set it to a default value. I used,(let 'c' be 'rating')
if(!results.hasOwnProperty('rating'))
results.rating = 1;
It works fine for elements that have 'rating' attribute. But for elements that dont have rating attribute, i get an error saying, 'Cannot find 'rating''.
Is there any other way to find whether the attribute is present or not?