为了账号安全,请及时绑定邮箱和手机立即绑定

在JavaScript中查找并替换嵌套数组对象

在JavaScript中查找并替换嵌套数组对象

有只小跳蛙 2021-04-08 13:13:44
如何在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}]
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 324 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信