Change the array data coming from the api

Asked

Viewed 58 times

1

I have a question in an application on React Native I’d like your help.

How do I increment a new item in the array that comes from the api.

The array of api today returns so:

data:[{ id:1, name:'product01'}, {id:2, name:'product02' }];

I’d like to put status within this array for each item. How can I do?

  • 1

    use the .map and make a new array

  • an example: https://answall.com/questions/460562/javascript-map

2 answers

2

  • 1

    Thank you very much, it was useful for me.

2

Complementing the reply of the colleague @novic can use the forEach(), as below:

const data = [{ id: 1, name: 'product01' }, { id: 2, name: 'product02'}];
data.forEach(item => item = Object.assign(item, { status: true }));
console.log(data);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.