score:2
Accepted answer
you could do it like this:
setmydata((prev) =>
prev.map((el) =>
el.orderid === "ord-898s2" ? { ...el, amount: el.amount + 100 } : el
)
);
score:0
try below code.
var data = [
{
"orderid": "ord-898s1",
"shoulder size": "12",
"amount": 200,
"shoulder width": "2",
},
{
"orderid": "ord-898s2",
"shoulder size": "14",
"amount": 790,
"shoulder width": "2",
}
];
var orderid = "ord-898s2"
var amounttoadd = 100
data.foreach((item) =>
item.orderid === orderid ? item.amount = item.amount + amounttoadd : item.amount);
console.log(data);
Source: stackoverflow.com
Related Query
- How to update value in array of object in useState hooks
- How to update value of a key in object in an array with the new value in React useState in TypeScript
- How do I update states `onChange` in an array of object in React Hooks
- How to update with React Hooks specific value of an array inside an object?
- React js useState hook. How to update state of a json object with an a array in it when a checkbox is clicked
- How do i update value of a key in an object inside an Array in React?
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to update specific object value of an array in javascript
- React - how to update a specific field in Object Array using useState in UseEffect
- How to update an existing array of objects (add a new object to the array) with the useState hook?
- How to update a useState which has an array, inside this array I have objects this objects will update when the input value will change in react js
- How to find and update specific value in nested object array in typescript
- How to change an object property in an array state container?? React Hooks useState
- update value of an object in an array - react hooks
- Update object value in useState array of objects
- How to update nested object having array with useState in Reactjs?
- Update object value in array React hooks way
- How to change update an object within a useState array
- How to update value array in object React js
- how to pass useState variable value to array of object field for INSERT data react.js and mysql?
- Update value in object array with useState
- How to update value in an object in an array using useState?
- How to update a single value of an object that is inside an array of objects
- how to update the state if dropdown has selected value with Hooks and useState
- How can I update an object in a nested array when an input value changes?
- How to use useState to only update specific object from array of objects?
- How to update single value inside specific array item in redux
- React efficiently update object in array with useState hook
- How to update state with usestate in an array of objects?
- How to dynamically update the value for any input field with one event handler function, using hooks
More Query from same tag
- React Native Firebase trying to show images from Firebase Storage
- Focus input after redux dispatch finished
- CSS: How to set url image properly to checked checkbox
- Can't call object method on previous state in setState hook inside subscribe body
- DOM Manipulation With `useEffect()` vs. `useLayoutEffect()`
- How to change Tabs Layout and Tab style in react bootstrap
- Redux Jest is not receiving value as expected
- travis cannot build because Error: Cannot find module 'react-test-renderer/shallow'
- Not able to save my new playlist in my Spotify account (I get an empty list of tracks)
- Editing input fields in react seeding with default
- How to render only specific components in Reactjs
- How can you update the props of a single element of an array using state?
- How to Use Tableau WDC in a ReactJs app the correct way
- Error Promise is not defined when I start my unit test on async action Redux
- How to properly set up material-ui with electron-react-boilerplate
- How to build specialized components in React
- React not doing deep comparing of defaultProps
- Loop through array to create React grid.
- docker compose erroring out about python files when starting React apps
- In JS ES6, why is it that if I export default, then I cannot export it individually?
- React Router Push Silently
- How does React Lazy fetch components?
- import App from './App';
- Toggle component with mapped data
- semantic-ui-react how to use form group inside a grid
- GooglePlacesAutocomplete - passing info to parent component and defining language
- Is this protecting route solution for Nextjs usable?
- React table with JSON subdocument data only
- React proxy request to back-end API to initiate Passport, Google OAuth2 request
- How to write `this.props` when rewriting class components to functional components with state hooks?