I am trying to convert following JSON data using map function into appropriate output
[{"jobId":100049,"name":"Drilling","jobNumber":"1222455","address":"Ahmedabad","city":"Ahmedabad","state":"1","zip":"38003","active":true,"jobOwnerId":100002,"jobOwnerName":"Troy Thomson","createdBy":"","createdOn":"2020-03-15T18:42:25.6533333","modifiedBy":"","modifiedOn":"2020-03-16T13:21:53.0333333","members":[{"memberId":100001,"memberName":"Hardik Gondalia"},{"memberId":100004,"memberName":"Micheal T. Angelo"}],"assets":[{"assetId":100004,"assetName":"Minima ullam non mol"}]},{"jobId":100051,"name":"Drilling The Hole","jobNumber":"11111","address":"201, AA 333 Steet, Time Square","city":"Boston","state":"1","zip":"11111","active":true,"jobOwnerId":100001,"jobOwnerName":"Hardik Gondalia","createdBy":"","createdOn":"2020-03-25T11:12:13.89","modifiedBy":"","modifiedOn":"2020-03-25T11:12:32.1266667","members":[{"memberId":100002,"memberName":"Troy Thomson"}],"assets":[{"assetId":100005,"assetName":"Drill Machine P2222"}]}]
Desired Output:
[{"jobid":100049,"memberid":100001],{"jobid":100049,"memberid":100004],{"jobid":100051,"memberid":100002]}
As you can see job is json object and have array of members and assets inside it. I want to repeat jobid if it has multiple member or assets.
What I've tried is:
const assignmentAssetModel = this.jobList.map(i => ({ jobid: i.jobId, assetid: i.assets.map(j => j.assetId) }));
But it gives me following output:
[{"jobid":100049,"memberid":[100001,100004]},{"jobid":100051,"memberid":[100002]}]
As you can I want to repeat jobid if it has more then one memberid