An Array and Object Method
In this article let us talk about a simple method about an array containing objects.
In the above picture, we can see that there is an object 'people'. the object has only only two properties. In an array called 'arr' we called the 'people' object four times. Then we displayed the result in console. Here is the result:
Now suppose that we change one property of an array. Here is the picture:
In line 8, we changed the value of an object in the array. After that what should be the output?
Well the name property has been changed in all the objects in the array. Since the same object has been declared in the array 4 times, one change has affected in all the values in the array.
Now suppose we have 2 objects, and we storing those objects in the array:
We again change one object value. So now it will affect that object's name property. Not will effect the other object. Here is the screenshot:
If we change one value from the array, it will effect all the object fields with the same name and property.