Skip to content
Advertisement

ReactJS Loop thru state array of object and add new field

I am learning reactjs and got an array of json object. I want to loop thru each record in the array, read the id and add/set a new field with a string value. When the looping is done, I will set the state to save the state collection. So far no luck in getting this to work.

Any help is greatly appreciated.

JavaScript

My goal is every record in OrginalRecords has a new json field called newField = ‘Test’.

Thanks

Advertisement

Answer

just do it like this using map function

JavaScript
Advertisement