확산 연산자를 사용하여 개체 배열에서 개체를 삭제하고 싶습니다.
다음과 같은 객체 배열이 있습니다.
const list= [
{
id: '1',
name: 'first_item',
},
{
id: '2',
name: 'second_item',
},
]
다음과 같이 "next_item"이라고 말하는 다른 개체를 추가 할 수 있습니다.
const next_item = {
id: '3',
name: 'next',
}
const final = [...list, next_item]
유사하게 목록에서 delete_item을 어떻게 삭제할 수 있습니까?
const delete_item = {
id: '2',
name: 'second_item',
},
누군가 나를 도울 수 있습니까? 감사.
스프레드 연산자에는 그런 것이 없지만 여전히 강제 하려면 여기에 있습니다.
var arrayObj = [1,2,3,4,5,6]
const index = arrayObj.findIndex(elm => elm === 5)
const removed = [...arrayObj.slice(0,index) ,
...arrayObj.slice(index+1,arrayObj.length)]
console.log(removed)
근데 이렇게 사용하면 득이 없어
다음 과 같은 일부 해체 기능을 사용할 수 있습니다 .
var arrayObj = [1,2,3,4,5,6,7];
var [first , second , ...rest ] = arrayObj;
console.log(first , second , rest);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다