Setter and Getter on Objects in Javascript

Set and Get methods can be used within an object to set or collect values from an element belonging to the object.

If an element of the object is an array, other elements of the object can be setter or getter methods that can add or display elements of the array.

It is also possible to delete a get or set method by using the reserved word delete followed by the name of the method to delete.

In the following example we have an object formed by an array element that can add colors and setter and getter elements to add or remove elements from that array of colors.

Comments

PHP Captcha


Interesting Articles