从数组中的数组中删除元素

从数组中的数组中删除元素

本文介绍了从数组中的数组中删除元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

****************已更新************************************************************** p

我在数组下有一个数组:

我想从子数组中删除一个元素,其中type ="tag"和name ="style".children array是下面打印的对象数组中的一个数组.

我的目标也是保持对象的原始阵列完整.

我正在使用以下代码,但它给了我未定义的内容:

 //对象的数组const responseText = html.parse(businessResponseText);console.log('responseText',responseText);//需要工作----如何转换此原始对象?const TransformationObject = {... responseText,子代:responseText.map((children)=> {children.children.filter(el =>el.type!=="tag"&&el.name!==样式")}) 

}

console.log('transformedobject',transformedObject);

这是我得到的输出:原始与转换

解决方案
  const transformList = styleFree.map(obj =>({... obj,子代:obj.children.filter(el =>el.type!=="tag"&&el.name!==样式")}) 

****************UPDATED*********************************************************

I have an array under an array:

I want to remove an element from children array where type="tag" and name="style". children array is an array within the array of objects printed below.

My aim is also to keep the original array of objects intact.

I am using the following code but it is giving me undefined:

// ARRAY of Objects
const responseText = html.parse(businessResponseText);


console.log('responseText',responseText);

// Needs work ---- how do I transform this original object?
const transformedObject = {
...responseText,
children: responseText.map((children)=>{
  children.children.filter(
    el => el.type !== "tag" && el.name !== "style"
)
})

}

console.log('transformedobject',transformedObject);

this is the output I get: original vs transformed

解决方案
const transformedList = styleFree.map(obj => ({
    ...obj,
    children: obj.children.filter(
        el => el.type !== "tag" && el.name !== "style"
    )
})

这篇关于从数组中的数组中删除元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:42