How to traverse through array within an object and return each array element as the second key value pair, along with its’ corresponding ID

I have an object that looks like this:

 {
      id: '100',
      domains: [
        'www.abc.com',
        'www.def.com'
      ]
    }
    { id: '101', domains: [ 'ghi.com' ] }
    {
      id: '102',
      domains: [ 'www.jkl.com' ]
    }
    ...

The final output should look like:

{ id: '100', url: 'abc.com' }
{ id: '100', url: 'def.com' }
{ id: '101', url: 'ghi.com' }
{ id: '102', url: 'jkl.com' }
...


Read more here: https://stackoverflow.com/questions/68486004/how-to-traverse-through-array-within-an-object-and-return-each-array-element-as

Content Attribution

This content was originally published by Umaesh S at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: