以下はMongodbのfindクエリで返されたjsonオブジェクトです。私はtreatList配列に新しいキーを追加したいと思います。Nodejsを使ってどのように達成できますか?Json配列に新しいキーを追加する
私が試みたtreatmentList [0] .push({新しいキー1: "新しい値1"})が、その動作していない
実際と期待される出力が以下に与えられる -
実際の出力
[
{
"departmentImagepath": "",
"treatmentList": [
{
"shortDescription": "my shortdescription",
"healingTimeInDays": "8",
},
{
"shortDescription": "my new shortdescription",
"healingTimeInDays": "10",
}
]
}
]
の予想される出力
あなたが得るJSONオブジェクトがに保存されていると仮定すると、[
{
"departmentImagepath": "",
"treatmentList": [
{
"shortDescription": "my shortdescription",
"healingTimeInDays": "8",
"new Key1": "new value1" //New key to be added
},
{
"shortDescription": "my new shortdescription",
"healingTimeInDays": "10",
"new Key2": "new value2" //New key to be added
}
]
}
]
http://idownvotedbecau.se/nomcve/ –
'のARR [0] [ "treatmentList"] [0] [ "新しいキー1"] = "新しい値1"' – kgangadhar
何とかそれが動作していない... –