Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js array map and update tat array value

const editSchoolName = (schools, oldName, name) =>
  schools.map(item => {
      if (item.name === oldName) {
        return {...item, name};
      } else {
        return item;
      }
});
Comment

js array map and update tat array value

const editSchoolName = ((schools, oldName, name) =>{
    let results =schools.map((item,index) => { 
        if (item.name === oldName) {
            let newItem = {...item, name} 
            return newItem;
    } else {
        return item;    
    }
    });
    return results;
});
Comment

js array map and update tat array value

let schools = [{
    name: 'YorkTown',
    country: 'Spain'
  },
  {
    name: 'Stanford',
    country: 'USA'
  },
  {
    name: 'Gymnasium Achern',
    country: 'Germany'
  }
];

let updatedSchools = [{
    name: 'New Gen',
    country: 'Spain'
  },
  {
    name: 'Stanford',
    country: 'USA'
  },
  {
    name: 'Gymnasium Achern',
    country: 'Germany'
  }
];

const editSchoolName = ((schools, oldName, name) =>{
  schools.map(item => {
    if (item.name === oldName) {
      item.name = name;
      return item.name;
    } else {
      return item;
    }
  });
  console.log(schools);
});

editSchoolName(schools, 'YorkTown', "New Gen");
 Run code snippet
Comment

js array map and update tat array value

const editSchoolName = (schools, oldName, newName) =>
    schools.map(({name, ...school }) => ({ ...school, name: oldName === name ? newName : name }));
Comment

PREVIOUS NEXT
Code Example
Javascript :: && in javascript new 
Javascript :: &nbsp replace javascript 
Javascript :: combine 2 data in column 
Javascript :: JS mixin implementation 
Javascript :: nodejs createwriteStream file image broken 
Javascript :: joining two array 
Javascript :: vue format number as dollars 
Javascript :: javascript get hours and minutes from date 
Javascript :: How to Use the Return Keyword in a Function 
Javascript :: what is react-instantsearch-dom 
Javascript :: JavaScript combining rows of multiple datasets 
Javascript :: react using props and parent state 
Javascript :: find parent index of nested array object javascript 
Javascript :: converting jsObject to JSON 
Javascript :: toggle checkbox react boolean 
Javascript :: javascript one linde condition 
Javascript :: javascript reduce mdn 
Javascript :: react email validation 
Javascript :: angularjs $q all hash 
Javascript :: unexpected text node: . a text node cannot be a child of a <view. 
Javascript :: delete all document fragments js 
Javascript :: react createelement data attribute 
Javascript :: javascript change favicon dynamicly 
Javascript :: move_uploaded_file equivalent in js 
Javascript :: deep copy array of objects javascript 
Javascript :: canvas squashed video javascript 
Javascript :: nodejs version abfragen 
Javascript :: how-can-i-implement-joi-password-complexity-in-joi-validation 
Javascript :: jquery on mouseover and mouseout 
Javascript :: return the remainder from two numbers javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =