gpt4 book ai didi

javascript - 如何获取键值,无论它位于数组中的哪个位置

转载 作者:行者123 更新时间:2023-12-02 22:42:56 24 4
gpt4 key购买 nike

捕获这个slice_type:部分。无论它在数组的哪个位置, 所以这里是 [1],但也可以是 [0] 或 [2]。最后我需要获取具有 slice_type: 'section'; 的对象中的项目键;

  [ { slice_type: 'structure',
slice_label: null,
items: [ [Object] ],
primary: {} },
{ slice_type: 'section', << Grab this slice_type section. No matter where it's in the array,
so here its [1], but it could be [0] or [2]. in the end I need to grab the items key that are in the object that has slice_type: 'section';
slice_label: null,
items:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ], <<- get this array of values
primary: { headline: [Array] } }

最佳答案

您可以使用过滤器和映射数组函数。

let result = arrays
.filter((obj) => obj["slice_type"] === "section") // filter by condition
.map(obj => obj.items);// return items of objects in filtered list

关于javascript - 如何获取键值,无论它位于数组中的哪个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58529671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com