Rakesh Nair Rakesh Nair - 1 year ago 80
JSON Question

Add a new attribute to json object

I have a

object of the following format


I need to add a new attribute to each row based on some calculations.

Expected result


How can I achieve this using

Answer Source

Use Array.prototype.forEach method:

.forEach(obj => {
  obj.field4 = 'Something'

Sidenote on terminology: you don't have any JSON, you have javascript array (object). JSON is a string representation of this object, but in your question you are talking about object itself.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download