Entry
How I use the method hasOwnProperty?
How I use the method hasOwnProperty?
Apr 15th, 2005 05:08
Martin Honnen,
The method hasOwnProperty takes one argument, the property name to check
for, and returns true if the XMLList object has a property of that name
and false otherwise.
Here are some examples:
var godList = <>
<god>
<name>Kibo</name>
<home>http://www.kibo.com/</home>
</god>
<devil>
<name>Kibo</name>
</devil>
</>;
alert(godList.hasOwnProperty('name')); // shows 'true'
alert(godList.hasOwnProperty('home')); // shows 'true'
alert(godList.hasOwnProperty('power')); // shows 'false'
alert(godList.hasOwnProperty('*')); // shows 'true'
alert(godList.hasOwnProperty('0')); // shows 'true'
alert(godList.hasOwnProperty('2')); // shows 'false'