如何在JavaScript中查找和替换深层嵌套数组对象我有一个示例对象名称,obj并按id, in , and out(obj_res)过滤了该对象。如何在javascript中使用id fundin查找和更新特定的obj,obj_res如预期的输出所示我陷入了需要帮助的情况下如何在javascript中做var obj_res = getValue("bank", "bank", "trans");function getValue(send, receive, id){ const temp = obj.map(e => Object.entries(e).map(([k, val]) => val)).flat(3) result_obj = temp.filter(x=>x.in ==send && && x=>x.out ==receive && x.id == id); return result_obj;}//whole object inputvar obj = [{ "btob": [{ "id": "trans", "in": "bank", "out": "bank", "value": 10, },{ "id": "fund", "in": "bank", "out": "bank", "value": 10 }], "ctob": [{ "id": "trans", "in": "credit", "out": "bank", "value": 20 },{ "id": "fund", "in": "credit", "out": "bank", "value": 10 }]}]//resultant obj after filter by id , in ,out var obj_res =[{ "id": "trans", "in": "bank", "out": "bank", "value": 10 },{ "id": "fund", "in": "bank", "out": "bank", "value": 10}] Expected Output: res=[{ "id": "trans", "in": "bank", "out": "bank", "value": 10 },{"id": "fund","in": "credit","out": "bank","value": 10}]
添加回答
举报
0/150
提交
取消