gpt4 book ai didi

azure 二头肌 : get array out of an array of objects

转载 作者:行者123 更新时间:2023-12-03 03:21:28 43 4
gpt4 key购买 nike

我有一个参数,它是一个对象数组。对象中的元素之一(“peers”)是另一个对象数组。我想动态提取对等数组并联合/连接它们并保留“vnetid”作为引用。

param vnets array = [
{
vnetid: 0
name: '0-test-test'
addressPrefix: '10.10.74.0/22'
peers: [
{
name: '0-to-1'
peerToId: 1
}
]
subnets: [
{
name: 'GatewaySubnet'
addressPrefix: '10.10.74.0/25'
}
{
name: 'AzureFirewallSubnet'
addressPrefix: '10.10.74.128/25'
}
]
}
{
vnetid: 1
name: '1-test-test'
addressPrefix: '10.10.68.0/22'
peers: [
{
name: '1-to-0'
peerToId: 0
}
]
subnets: [
{
name: 'subnet1'
addressPrefix: '10.10.68.0/25'
}
{
name: 'subnet2'
addressPrefix: '10.10.69.0/24'
}
]
}
]

所需的新数组:

param peers array = [
{
vnetid: 0
name: '0-to-1'
peerToId: 1
}
{
vnetid: 1
name: '1-to-0'
peerToId: 0
}
]

我找不到解决方案。我尝试过 concat、union、items 和基本上所有的数组函数。没有任何运气。

最佳答案

您可以使用mapflatten lambda 函数如所述 here :

var peers = flatten(
// Iterate through the vnets
map(vnets, vnet =>
// Iterate through the peers and add vnetid to the peer object
map(vnet.peers, peer =>
union({ vnetid: vnet.vnetid }, peer)
)
)
)

output peers array = peers

关于 azure 二头肌 : get array out of an array of objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77163146/

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