gpt4 book ai didi

javascript - jquery 删除 JSON 元素

转载 作者:行者123 更新时间:2023-11-28 14:44:08 26 4
gpt4 key购买 nike

我有这样的 JSON:

[{"name":"tanggalPengajuan","value":""},{"name":"namaPemohon","value":""},{"name":"unitKerja","value":""},{"name":"nomorTelepon","value":""}]

如何删除元素名称所以我会得到像这样的“普通 JSON”:

[{
"tanggalPengajuan" :"my date here",
"namaPemohon" :"My name here",
"unitKerja" :"My unit here",
"nomorTelepon" :"my number here"
}]

最佳答案

您可以使用Array.prototype.map()为了这。

对于原始数组中的每个元素,您可以创建一个新对象,其属性 name 和值为 value

var data = [{"name":"tanggalPengajuan","value":"abc"},{"name":"namaPemohon","value":""},{"name":"unitKerja","value":""},{"name":"nomorTelepon","value":""}];

console.log(data.map(function(t){
var obj = {};
obj[t.name] = t.value;
return obj;
}));

关于javascript - jquery 删除 JSON 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47107370/

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