Skip to content
Advertisement

Add property to an array of objects

I have an array of objects as shown below

JavaScript

I want to add one more property named Active to each element of this array of Objects.

The final outcome should be as follows.

JavaScript

Can someone please let me know how to achieve this.

Advertisement

Answer

You can use the forEach method to execute a provided function once for each element in the array. In this provided function you can add the Active property to the element.

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement