March 12, 2001 - Checking for an Enumerable Property | WebReference

March 12, 2001 - Checking for an Enumerable Property

Yehuda Shiran March 12, 2001
Checking for an Enumerable Property
Tips: March 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

An object's property may be enumerable. An enumerable property can assume only predefined values from a given list. The variable a is enumerable:

a = new Array("jan", "feb", "march");

It can assume one of three values only: "jan", "feb", or "march". The following script defines the object Employee, where the property month is enumerable:

function Employee() {
  this.dept = "HR";
  this.manager = "John Johnson";
  this.month = new Array("jan", "feb", "mar");
}
var Ken = new Employee();

You can verify that indeed month is enumerable by:

Ken.month.propertyIsEnumerable(0);

The parameter of the method above should be numeric. Try it.