Skip to content
Advertisement

Merge arrays from object property in an object array [closed]

Give an array of objects as below:

JavaScript

I would like to get an array of merged items from fields property and output should be 1, 2, 3, 4

I’ve tried to merge as below. I’m not satisfied with my solution and would like to get feedback’s and improve upon my solution. I’m new to JS and typescript. I believe there is better solution with features of ES6. Can someone help to improve my solution?

JavaScript

Advertisement

Answer

You can simply concat the array and create a new array inside a loop:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement