es6
-
JS/자주쓰는 scriptLanguage/Java Script 2022. 10. 28. 14:27
기본 데이터 const items = [ {id: 0, name: 'name0'}, {id: 1, name: 'name1'}, {id: 2, name: 'name2'} ]; const tempItem = { id: 1, name: 'name1' }; findIndex let newItems = [...items]; const findIndex = newItems.findIndex((x) => x.id === tempItem.id); newItems[findIndex].name = '테스트'; Object.values & filter const result = Object.values(items).filter((item) => { if (item.id === tempItem.id) { return true..