Every programming element is important. However, the array is special. It enables you to use a single variable to refer the storage of multiple variables. With an array, it has become much easier to handle multiple values. There are some limitations of this referenced data type. This is the reason why Java, C#, and other high-level languages rely on objects to store values of different primitive data types. However, still, arrays are very important element of middle and high-level programming languages.
Adding Custom Properties to Array
Indices of an array
Predefined or built-in properties
Every beginner developer is familiar with the first two properties. Experienced developers regularly use all three properties.
Indices as Properties
var ary = [“eyes”,”hands”,”ears”];
There are two ways for accessing built-in properties:
In var ary = [“eyes”,”hands”,”ears”];
ary.length will return 3 and ary[“length”] will also return 3.
Adding Custom Properties
In the following example, we have created a property to identify the class of an array.
console.log(ary+ ”are” +ary.itemClass);
The output will be “eyes, hands, ears are bodyParts”