Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change object in array in state

const toggleDone = (id) => {
  console.log(id);

  // loop over the todos list and find the provided id.
  let updatedList = state.todos.map(item => 
    {
      if (item.id == id){
        return {...item, done: !item.done}; //gets everything that was already in item, and updates "done"
      }
      return item; // else return unmodified item 
    });

  setState({todos: updatedList}); // set state to new object with updated list
}
Comment

change value in array react

setOfficeSpace([...officeSpace, { ...item, number: 1, type: item.key }]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: google places API details JS 
Javascript :: javascript learning 
Javascript :: push pop in javascript 
Javascript :: javascript no decimal places 
Javascript :: Multiple functions in javascript onclick 
Javascript :: mongoose remove 
Javascript :: SELECT * FROM USERSs 
Javascript :: react native scrollview item bottom 
Javascript :: how to do division in javascript 
Javascript :: find function in javascript 
Javascript :: angular set timezone 
Javascript :: how to get nested array using lodash 
Javascript :: mvc asp.net partial view from js 
Javascript :: how to unfreeze object in javascript 
Javascript :: open modal using jquery 
Javascript :: how to store variable in local storage angualur 
Javascript :: ilan mask 
Javascript :: javascript scrape page 
Javascript :: show password using javascript 
Javascript :: javascript callback 
Javascript :: how to get length in js without using .length method 
Javascript :: min in array 
Javascript :: && in javascript 
Javascript :: js if 
Javascript :: how to remove the elements from array and how to replace a new element in javascript 
Javascript :: javascript check string sort ascending 
Javascript :: favicon express js 
Javascript :: react-google-invisible-recaptcha 
Javascript :: scraping google nodejs 
Javascript :: react native textinput disable keyboard 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =