首页 > 解决方案 > how to push array of objects inside an object to an array with unique index js

问题描述

Question Explained:

I am doing a "for Each" loop to iterate key values and appending it with the api to get the response which is a single object. This object has a field called "issuselinks" which is a array of objects. My problem here is.. instead of storing the response object in an array i want to store the objects inside the "issueLinks" array into an array with separate index of each obj (i.e) issulinks[0] vaalue should sit in array[0] without looping the issuelinks. Thus my new array should contain objects of "issuselinks" instead of the whole response object. And I dont want to loop "issueLinks" and store it in a array since i already have more looping logic inside and which might go async. And if possible please tell me how to avoid loops.. which is going async. Thanks in advance!!

Here is my sample JSON Object:

{
    "fields": {
        "issuelinks": [
            {
                "id": "378753"
            },
            {
                "id": "378752"
            }
        ],
        "assignee": null,
        "customfield_10600": "9223372036854775807",
        "customfield_12109": null,
        "aggregatetimeestimate": null,
        "comment": {
            "comments": [],
            "maxResults": 0,
            "total": 0,
            "startAt": 0
        }
    },
    "customfield_10290": null,
        "customfield_10291": null,
        "customfield_10171": null,
        "customfield_10053": "Req 21",
        "customfield_10450": null,
        "customfield_10451": null,
        "customfield_10332": null,
        "customfield_10453": null,
        "customfield_11300": null,
        "customfield_10455": null,
        "customfield_12107": null,
}

标签: javascriptnode.js

解决方案


推荐阅读