in special operator
Property exists in object or its prototype chain.
Description
The in special operator returns true if the specified property is in the specified object or its prototype chain, or false otherwise.
- For any property of an object that is marked as
undefinedwill still returntrueas the property still exists.
Syntax
| Signature | Description |
|---|---|
propertyName in objectName | The in special operator returns true if the specified property is in the specified object or its prototype chain, or false otherwise. |
Parameters
| Parameter | Description |
|---|---|
propertyName | The name of the property.
|
objectName | The object to locate the property in. |
Examples
Following are examples of the in special operator.
// The in special operator.
var anArray = new Array('fred','ned','ted','jed');
var aString = new String('awesome');
var inArray = new Array(6);
inArray[0] = 'fred' in inArray; // false, need to search element index
inArray[1] = 0 in inArray; // true, this element index exists
inArray[2] = 4 in inArray; // false, this element index does not exist
inArray[3] = 'constructor' in inArray; // true, constructor Array property
inArray[4] = 'length' in aString; // true, length is a String property
inArray[5] = 'prototype' in Object; // // true, prototype Object property
alert(inArray);
