Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to post an array with some object when I have an array with id, using angular

I need your opinion how to post an array with some object.

I have this code:

 const selectedJobs = this.ms.selectedItems;
    if (!selectedJobs) {
      return;
    }
    const selectedJobsId = selectedJobs.map((jobsId) =>
      jobsId.id
    );

in this case I get all jobId like an array ['618e2ee9', '3ee199b7']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    const payload = [
      {
        jobId: selectedJobsId,
        state: 2,
      }
    ];

from payload I get an array with one object that have inside an array with JobsId and state. As below

 [
    {
        "jobId": [
            "618e2ee9",
            "3ee199b7"
        ],
     "state": 2
    }
]

I should get this response, one array with all objects. all jobs id to be objects:

[
    {
       "jobId": "618e2ee9",
        "state": 2
    },
    {
      "jobId":  "3ee199b7",
    "state": 2
    }
 ]

Have you any idea please?

>Solution :

Try this

    const payload = selectedJobsId.map(job => 
                        { 
                          return {jobId: job, state: 2};
                         });
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading