如何避免在React中覆盖A&#XSON对象?

发布于 2025-02-08 10:48:46 字数 12811 浏览 2 评论 0原文

我正在比较第二个JSON的两个JSON并将不匹配的值与一个键中的不匹配值一起存储在新的JSON对象中。我正在使用一个循环来比较两个JSON对象。如果有多个差异,则被先前存储的对象覆盖。您能告诉我如何解决吗?

    var finalOutputJson;
let jsonOutput1 = {},
  jsonOutput2 = {};


for (let i of jsonData1) {
      var d = jsonData2.filter(
        (data) => data.Unique == i.Unique
      );      
      if (d != []) {
        let keys = Object.keys(i);
        for (let j of keys) {
          if (j == "Title") {
            if (i[j] != d[0]["Name"].Title) {          
             jsonOutput1 = { [j]: d[0]["Name"].Title };
              console.log(jsonOutput1);
            }
          } else if (i[j] != d[0][j]) {            
            jsonOutput2 = { [j]: d[0][j] };            
            console.log(jsonOutput2);
          }


[![jsonOutput1][1]][1]

inputjsondata1: -

[
    {
        "Title": "Ankit Singh1",
        "Aadhar_x0020_Nuber": 999941057058,
        "Age": 54,
        "Gender": "M",
        "Phone": 2810806979,
        "Father_x0020_Name": "Mr. Choudhury",
        "Email": "[email protected]",
        "City": "New Delhi",
        "State": "New delhi"
    },
    {
        "Title": "Munendra",
        "Aadhar_x0020_Nuber": 999971658847,
        "Age": 44,
        "Gender": "M",
        "Phone": 2314475929,
        "Father_x0020_Name": "Mr. Agarwal",
        "Email": "[email protected]",
        "City": "Udaipur",
        "State": "Rajasthan"
    },
    {
        "Title": "Mayank Sharma3",
        "Aadhar_x0020_Nuber": 999933119405,
        "Age": 79,
        "Gender": "F",
        "Phone": 2837032088,
        "Father_x0020_Name": "Mr. Bedi",
        "Email": "[email protected]",
        "City": "Bareilly",
        "State": "Uttar Pradesh"
    },
    {
        "Title": "Shikhar Saxena5",
        "Aadhar_x0020_Nuber": 999955183433,
        "Age": 37,
        "Gender": "M",
        "Phone": 2821096353,
        "Father_x0020_Name": "Mr. Pandey",
        "Email": "[email protected]",
        "City": "Mumbai",
        "State": "Maharastra"
    },
    {
        "Title": "Namita Rastogi",
        "Aadhar_x0020_Nuber": 999990501894,
        "Age": 40,
        "Gender": "F",
        "Phone": 2821096350,
        "Father_x0020_Name": "Mr. Kapoor",
        "Email": "[email protected]",
        "City": "Bangalore",
        "State": "Karnataka"
    }
]

inputjsondata2: -

[
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "1a8bda26-b339-4e95-a42e-cf8b15aa571c",
        "odata.etag": "\"3\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(1)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(1)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "e0fc5839-8528-460f-9a97-735b3e676870",
            "Title": "Ankit Singh"
        },
        "FileSystemObjectType": 0,
        "Id": 1,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 1,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-07T09:31:14Z",
        "Created": "2022-06-02T08:15:05Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "3.0",
        "Attachments": false,
        "GUID": "c27f786a-8599-400c-b284-f7bec308a861",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999941057058,
        "NameId": 1282,
        "NameStringId": "1282",
        "Age": 54,
        "Gender": "M",
        "Phone": 2810806979,
        "Father_x0020_Name": "Mr. Choudhury",
        "Email": "[email protected]",
        "City": "New Delhi",
        "State": "New delhi"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "bbb3d19c-5fae-463b-993a-08e3665f4997",
        "odata.etag": "\"2\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(2)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(2)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "f9f74da9-4aba-4cdc-8e4f-2985883c4602",
            "Title": "Munendra"
        },
        "FileSystemObjectType": 0,
        "Id": 2,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 2,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-16T06:40:16Z",
        "Created": "2022-06-02T08:17:48Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "2.0",
        "Attachments": false,
        "GUID": "afb84bd6-0253-4bf8-a515-824b13ae1a4e",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999971658847,
        "NameId": 107,
        "NameStringId": "107",
        "Age": 44,
        "Gender": "F",
        "Phone": 2314475929,
        "Father_x0020_Name": "Mr. Agarwal",
        "Email": "[email protected]",
        "City": "Udaipur",
        "State": "Rajasthan"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "49217d7e-200c-496b-b728-bd5307bbe1db",
        "odata.etag": "\"1\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(3)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(3)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "df5b1286-0009-48ba-a7bc-7b269a9ebcf7",
            "Title": "Mayank Sharma3"
        },
        "FileSystemObjectType": 0,
        "Id": 3,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 3,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-02T08:18:58Z",
        "Created": "2022-06-02T08:18:58Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "e5ac3af3-e024-4703-b946-96cdc2ff3b5e",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999933119405,
        "NameId": 705,
        "NameStringId": "705",
        "Age": 79,
        "Gender": "M",
        "Phone": 2837032088,
        "Father_x0020_Name": "Mr. Bedi",
        "Email": "[email protected]",
        "City": "Bareilly",
        "State": "Uttar Pradesh"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "e1f7ffaa-1bc7-4afa-bccb-18965f13c750",
        "odata.etag": "\"1\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(4)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(4)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "5f9e7c49-9bde-4b66-90c8-12e156db60ce",
            "Title": "Shikhar Saxena"
        },
        "FileSystemObjectType": 0,
        "Id": 4,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 4,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-02T08:20:16Z",
        "Created": "2022-06-02T08:20:16Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "c3395b35-a981-4754-abb5-8b4b0fe65a51",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999955183433,
        "NameId": 846,
        "NameStringId": "846",
        "Age": 37,
        "Gender": "M",
        "Phone": 2821096353,
        "Father_x0020_Name": "Mr. Pandey",
        "Email": "[email protected]",
        "City": "Mumbai",
        "State": "Maharastra"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "29ba7f05-52e8-4ded-b3e5-22a9b3001d97",
        "odata.etag": "\"2\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(5)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(5)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "cdce69d7-a601-4c9f-ad03-0a85eccb510b",
            "Title": "Namita Rastogi"
        },
        "FileSystemObjectType": 0,
        "Id": 5,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 5,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-09T07:25:17Z",
        "Created": "2022-06-02T08:21:46Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "2.0",
        "Attachments": false,
        "GUID": "7a7d7906-442e-41eb-9f17-16f729fbb310",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999990501894,
        "NameId": 849,
        "NameStringId": "849",
        "Age": 40,
        "Gender": "F",
        "Phone": 2821096351,
        "Father_x0020_Name": "Mr. Kapoor",
        "Email": "[email protected]",
        "City": "Bangalore",
        "State": "Karnataka"
    }
]

预期输出: -

[
    {
        "Title": "Ankit Singh",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "F",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "M",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "Shikhar Saxena",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": 2821096351,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    }
]

I'm comparing two JSON and returning mismatched values from the second JSON with a key and storing them in a new JSON object. I'm using a loop for comparing two JSON objects. If there is more than one difference, it is overwritten by the previous object stored. Can you please tell me how to resolve it?

    var finalOutputJson;
let jsonOutput1 = {},
  jsonOutput2 = {};


for (let i of jsonData1) {
      var d = jsonData2.filter(
        (data) => data.Unique == i.Unique
      );      
      if (d != []) {
        let keys = Object.keys(i);
        for (let j of keys) {
          if (j == "Title") {
            if (i[j] != d[0]["Name"].Title) {          
             jsonOutput1 = { [j]: d[0]["Name"].Title };
              console.log(jsonOutput1);
            }
          } else if (i[j] != d[0][j]) {            
            jsonOutput2 = { [j]: d[0][j] };            
            console.log(jsonOutput2);
          }


[![jsonOutput1][1]][1]

jsonOutput2

inputJsonData1 :-

[
    {
        "Title": "Ankit Singh1",
        "Aadhar_x0020_Nuber": 999941057058,
        "Age": 54,
        "Gender": "M",
        "Phone": 2810806979,
        "Father_x0020_Name": "Mr. Choudhury",
        "Email": "[email protected]",
        "City": "New Delhi",
        "State": "New delhi"
    },
    {
        "Title": "Munendra",
        "Aadhar_x0020_Nuber": 999971658847,
        "Age": 44,
        "Gender": "M",
        "Phone": 2314475929,
        "Father_x0020_Name": "Mr. Agarwal",
        "Email": "[email protected]",
        "City": "Udaipur",
        "State": "Rajasthan"
    },
    {
        "Title": "Mayank Sharma3",
        "Aadhar_x0020_Nuber": 999933119405,
        "Age": 79,
        "Gender": "F",
        "Phone": 2837032088,
        "Father_x0020_Name": "Mr. Bedi",
        "Email": "[email protected]",
        "City": "Bareilly",
        "State": "Uttar Pradesh"
    },
    {
        "Title": "Shikhar Saxena5",
        "Aadhar_x0020_Nuber": 999955183433,
        "Age": 37,
        "Gender": "M",
        "Phone": 2821096353,
        "Father_x0020_Name": "Mr. Pandey",
        "Email": "[email protected]",
        "City": "Mumbai",
        "State": "Maharastra"
    },
    {
        "Title": "Namita Rastogi",
        "Aadhar_x0020_Nuber": 999990501894,
        "Age": 40,
        "Gender": "F",
        "Phone": 2821096350,
        "Father_x0020_Name": "Mr. Kapoor",
        "Email": "[email protected]",
        "City": "Bangalore",
        "State": "Karnataka"
    }
]

inputJsonData2:-

[
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "1a8bda26-b339-4e95-a42e-cf8b15aa571c",
        "odata.etag": "\"3\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(1)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(1)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "e0fc5839-8528-460f-9a97-735b3e676870",
            "Title": "Ankit Singh"
        },
        "FileSystemObjectType": 0,
        "Id": 1,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 1,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-07T09:31:14Z",
        "Created": "2022-06-02T08:15:05Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "3.0",
        "Attachments": false,
        "GUID": "c27f786a-8599-400c-b284-f7bec308a861",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999941057058,
        "NameId": 1282,
        "NameStringId": "1282",
        "Age": 54,
        "Gender": "M",
        "Phone": 2810806979,
        "Father_x0020_Name": "Mr. Choudhury",
        "Email": "[email protected]",
        "City": "New Delhi",
        "State": "New delhi"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "bbb3d19c-5fae-463b-993a-08e3665f4997",
        "odata.etag": "\"2\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(2)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(2)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "f9f74da9-4aba-4cdc-8e4f-2985883c4602",
            "Title": "Munendra"
        },
        "FileSystemObjectType": 0,
        "Id": 2,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 2,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-16T06:40:16Z",
        "Created": "2022-06-02T08:17:48Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "2.0",
        "Attachments": false,
        "GUID": "afb84bd6-0253-4bf8-a515-824b13ae1a4e",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999971658847,
        "NameId": 107,
        "NameStringId": "107",
        "Age": 44,
        "Gender": "F",
        "Phone": 2314475929,
        "Father_x0020_Name": "Mr. Agarwal",
        "Email": "[email protected]",
        "City": "Udaipur",
        "State": "Rajasthan"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "49217d7e-200c-496b-b728-bd5307bbe1db",
        "odata.etag": "\"1\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(3)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(3)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "df5b1286-0009-48ba-a7bc-7b269a9ebcf7",
            "Title": "Mayank Sharma3"
        },
        "FileSystemObjectType": 0,
        "Id": 3,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 3,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-02T08:18:58Z",
        "Created": "2022-06-02T08:18:58Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "e5ac3af3-e024-4703-b946-96cdc2ff3b5e",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999933119405,
        "NameId": 705,
        "NameStringId": "705",
        "Age": 79,
        "Gender": "M",
        "Phone": 2837032088,
        "Father_x0020_Name": "Mr. Bedi",
        "Email": "[email protected]",
        "City": "Bareilly",
        "State": "Uttar Pradesh"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "e1f7ffaa-1bc7-4afa-bccb-18965f13c750",
        "odata.etag": "\"1\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(4)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(4)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "5f9e7c49-9bde-4b66-90c8-12e156db60ce",
            "Title": "Shikhar Saxena"
        },
        "FileSystemObjectType": 0,
        "Id": 4,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 4,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-02T08:20:16Z",
        "Created": "2022-06-02T08:20:16Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "c3395b35-a981-4754-abb5-8b4b0fe65a51",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999955183433,
        "NameId": 846,
        "NameStringId": "846",
        "Age": 37,
        "Gender": "M",
        "Phone": 2821096353,
        "Father_x0020_Name": "Mr. Pandey",
        "Email": "[email protected]",
        "City": "Mumbai",
        "State": "Maharastra"
    },
    {
        "odata.type": "SP.Data.Aadhar_x005f_DataListItem",
        "odata.id": "29ba7f05-52e8-4ded-b3e5-22a9b3001d97",
        "odata.etag": "\"2\"",
        "odata.editLink": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(5)",
        "[email protected]": "Web/Lists(guid'f57b8a37-9a12-48fa-ae4a-f2c360611fd2')/Items(5)/Name",
        "Name": {
            "odata.type": "SP.Data.UserInfoItem",
            "odata.id": "cdce69d7-a601-4c9f-ad03-0a85eccb510b",
            "Title": "Namita Rastogi"
        },
        "FileSystemObjectType": 0,
        "Id": 5,
        "ServerRedirectedEmbedUri": null,
        "ServerRedirectedEmbedUrl": "",
        "ID": 5,
        "ContentTypeId": "0x0100CAEC71E55732C14BA36095D2FA8E6CA80037B4C7B1E7CFFA4D83E55D30CD77AC99",
        "Title": null,
        "Modified": "2022-06-09T07:25:17Z",
        "Created": "2022-06-02T08:21:46Z",
        "AuthorId": 1282,
        "EditorId": 1282,
        "OData__UIVersionString": "2.0",
        "Attachments": false,
        "GUID": "7a7d7906-442e-41eb-9f17-16f729fbb310",
        "ComplianceAssetId": null,
        "Aadhar_x0020_Nuber": 999990501894,
        "NameId": 849,
        "NameStringId": "849",
        "Age": 40,
        "Gender": "F",
        "Phone": 2821096351,
        "Father_x0020_Name": "Mr. Kapoor",
        "Email": "[email protected]",
        "City": "Bangalore",
        "State": "Karnataka"
    }
]

Expected Output:-

[
    {
        "Title": "Ankit Singh",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "F",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "M",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "Shikhar Saxena",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": ,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    },
    {
        "Title": "",
        "Aadhar_x0020_Nuber": ,
        "Age": ,
        "Gender": "",
        "Phone": 2821096351,
        "Father_x0020_Name": "",
        "Email": "",
        "City": "",
        "State": ""
    }
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以往的大感动 2025-02-15 10:48:46

您每次都为jsonoutput1 jsonoutput2 分配一个新值。您要添加到现有对象中,在这种情况下,您需要更改行:

jsonOutput1 = { [j]: d[0]["Name"].Title };

同样

jsonOutput1[j] = d[0]["Name"].Title;

,还要更新jsonOutput2行的代码。

您可以参考此

希望这将起作用。

You are assigning a new value to the jsonOutput1 and jsonOutput2 everytime. You want to add to the existing object, in that case you need to change the lines:

jsonOutput1 = { [j]: d[0]["Name"].Title };

to

jsonOutput1[j] = d[0]["Name"].Title;

Similarly update the code for your jsonOutput2 line as well.

You can refer to this MDN JavaScript Guide Documentation and refer to the part where there demonstrate how to create additional properties in an existing object.

Hopefully, this will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文