gpt4 book ai didi

javascript - 如何从数组中提取对象?

转载 作者:行者123 更新时间:2023-11-30 09:13:10 26 4
gpt4 key购买 nike

<分区>

我需要从对象数组(“types”)中删除一些对象并创建另一个名为“newtypes”的数组

let types = [
{value:"a", label:"xxx", component: "Demographic"},
{value:"b", label:"xxx", component: "Elastic"},
{value:"c", label:"xxx", component: "Another"},
{value:"d", label:"xxx", component: "Another2"},
];

let props = [{user : {new_functions_id: [
{component: "Demographic", function_count: 4, new_functions_id: 2},
{component: "Elastic", function_count: 2, new_functions_id: 1},
]}}
];
console.log(types);
console.log(props);

/*
I have to create this var:

let newtypes = [
{value:"a", label:"xxx", component: "Demographic"},
{value:"b", label:"xxx", component: "Elastic"},
];

*/

我正在尝试循环数组:

newtypes = types.map( a => {
if(a.component == b.component)

});

但我一直在思考如何比较或检查第二个数组的值是否在第一个数组中。

26 4 0
文章推荐: javascript - 使用链式 JavaScript Promises 淡出/淡入图像
文章推荐: javascript - 下拉菜单的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com