2

Given this data:

const array1 = [
  { "issueKey": "ESM-37" },
  { "issueKey": "ESM-36" },
  { "issueKey": "ESM-35" },
  { "issueKey": "ESM-30" }
];

const array2 = [
  { "statusId": "1" },
  { "statusId": "1" },
  { "statusId": "2" },
  { "statusId": "2" }
];

How could I get this result?

const desiredResult = [
  {
    "issueKey": "ESM-37",
    "statusId": "1"
  },
  {
    "issueKey": "ESM-36",
    "statusId": "1"
  },
  {
    "issueKey": "ESM-35",
    "statusId": "1"
  },
  {
    "issueKey": "ESM-30",
    "statusId": "1"
  }
];
D M
  • 5,769
  • 4
  • 12
  • 27
  • 3
    Should `ESM-35` and `ESM-30` have `statusId: 2` instead of `statusId: 1`? – D M Apr 19 '22 at 19:59
  • 4
    Does this answer your question? [JavaScript merging objects by id](https://stackoverflow.com/questions/19480008/javascript-merging-objects-by-id) The solution to the current question is even more simple since it's based on index. – Yogi Apr 19 '22 at 20:01
  • 1
    to OP - next time, don't tag `karate` questions as `javascript` - it will save you some trouble – Peter Thomas Apr 20 '22 at 04:26
  • @D M, yes. I tried to edit, but I get the 'It looks like your post is mostly code; please add some more details.' Thank you for pointing it out. - late hours – Sathish Sevukan Apr 20 '22 at 05:45

1 Answers1

1

This code does the job:

const desiredResult = array1.map((it, i) => ({...it, ...array2[i]}))
Caio Santos
  • 1,665
  • 15
  • 10