因为我在map中有4个键/值,所以我尝试以字符串格式存储两个键,并将其余两个存储在一个数组中。
{ url: 'account/43',
status: '200',
headers: '\'content-type\' = \'application/json\'',
body: '{ name: Fatma Zaman }' }
预期输出:
{ url: 'account/43',
status: '200',
headers: [ '\'content-type\' = \'application/json\'' ],
body: [ '{ "name": "Fatma Zaman" }' ]}
下面是返回字符串中所有键/值对的代码,我可以将所有键/值对都放在数组中,但不确定如何只将两个键的值转换为数组。
function processFile(content) {
lodash.forEach(content, function(node) {
if (node.startsWith("//")) {
key = node.substring(2, node.length - 2).toLowerCase().trim()
return
} else {
value = node
}
map[key] = value
})
console.log(lodash.map(map, "key"))
return map
}
https://stackoverflow.com/questions/50662283
复制相似问题