json 배열 특정 키 및 데이터 삭제
카테고리 없음2021. 3. 11. 10:52
JSON 배열을 일종의 목록이라고 보고 특정 열 전체를 삭제하고 싶을 때 아래와 같이 간단하게 처리 가능
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | const arr = [ { XXX: "2" , YYY: "3" , ZZZ: "4" }, { XXX: "5" , YYY: "6" , ZZZ: "7" }, { XXX: "1" , YYY: "2" , ZZZ: "3" } ] // destructure 'YYY' and return the other props only const newArray = arr.map(({YYY, ...rest}) => rest) console.log(newArray) |
[참고]
https://stackoverflow.com/questions/24770887/remove-key-value-pair-from-json-object