An Array and Object Method

An Array and Object Method

In this article let us talk about a simple method about an array containing objects.

Array Containing Object

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:

Array Object Output

Now suppose that we change one property of an array. Here is the picture:

No alt text provided for this image

In line 8, we changed the value of an object in the array. After that what should be the output?

Object Array new value assign

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:

Double Objects

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:

Double objects in an array

If we change one value from the array, it will effect all the object fields with the same name and property.

To view or add a comment, sign in

More articles by Md. Tahmid Chowdhury

  • Higher Order Components (HOC)

    What is Higher Order Component(HOC)? It is an advanced method of reusing the component functionality logic. It takes…

    1 Comment
  • Converting an Object to an Array

    Suppose We have an Object. The object is given below: The object name is 'avengers'.

  • Node.js Stream

    Streams is a pure NodeJS concept. Nodejs is a runtime environment and it uses JavaScript.

    2 Comments

Explore content categories