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']
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?
CodePudding user response:
Try this
const payload = selectedJobsId.map(job =>
{
return {jobId: job, state: 2};
});
CodePudding user response:
const desiredArray = selectedJobs.map(job => {jobId:job.id, state:job.state} );