鑒于以下情況:
輸入:
[
[
{
"type": "strip",
"output": "debian-7-x86_64-strip"
},
{
"type": "compress",
"output": "debian-7-x86_64-compress"
},
{
"type": "full",
"output": "debian-7-x86_64"
}
],
[
{
"type": "strip",
"output": "debian-8-strip"
},
{
"type": "compress",
"output": "debian-8-compress"
}
]
]
如何在洗掉最后一個物件項(從每個子陣列中)重新創建陣列?
期望輸出:
[
[
{
"type": "strip",
"output": "debian-7-x86_64-strip"
},
{
"type": "compress",
"output": "debian-7-x86_64-compress"
}
],
[
{
"type": "strip",
"output": "debian-8-strip"
}
]
]
我試過使用... |= .[:-1]和這樣的東西...[to_entries | last],... | select(last|not)但我沒有成功。
非常感謝您的幫助。
uj5u.com熱心網友回復:
.[][0:-1] 讓你走得更遠,只是在輸出中缺少周圍的陣列。
編輯:[.[][:-1]]應該這樣做。
uj5u.com熱心網友回復:
試試 javascript pop 函式。所需的結果將是陣列arr。
const arr = [
[
{
"type": "strip",
"output": "debian-7-x86_64-strip"
},
{
"type": "compress",
"output": "debian-7-x86_64-compress"
},
{
"type": "full",
"output": "debian-7-x86_64"
}
],
[
{
"type": "strip",
"output": "debian-8-strip"
},
{
"type": "compress",
"output": "debian-8-compress"
}
]
]
for(var i=0;i<arr.length;i ){
arr[i].pop();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/366635.html
上一篇:R-查詢JSON并保存到變數
