我尝试检索参数数组值,其中键为eventName
,值为become_member
。到目前为止,我能够实现以下输出。我无法从参数数组中检索值。
//Output
["GA4 Tag", "12", [{
key: "sendEcommerceData",
type: "boolean",
value: "false"
}, {
key: "eventName",
type: "template",
value: "become_vip_member"
}, {
key: "measurementId",
type: "tagReference",
value: "GA4 - Config - SS - Dummy"
}], "1234564", "89", "1898989"]
实际的输出应该类似于以下内容:
Final Output Required: [GA4 Tag,12,become_member,1234564,89,1898989]
Final Output Fields: [Tag, WorkspaceId, Event Name, Container ID, Tag ID, Account ID]
//Data from the API
var tags = {
"name":"GA4 Tag",
"workspaceId": "12",
"parameter": [{
"type": "boolean",
"key": "sendEcommerceData",
"value": "false"
}, {
"key": "eventName",
"type": "template",
"value": "become_member"
}, {
"key": "measurementId",
"type": "tagReference",
"value": "GA4 - Config - SS - Dummy"
}],
"containerId": "1234564",
"tagId": "89",
"accountId": "1898989"
}
//Code
const keys = Object.keys(tags);
console.log(keys);
const rows = []
keys.forEach(function(key) {
console.log(tags[key]);
rows.push(tags[key]);
console.log(rows);
})
1条答案
按热度按时间dy1byipe1#
parameter
是对象数组。可以使用find
查找键为eventName
的对象,并返回其值。