Skip to content
Advertisement

I have a mixed type of array object. I need to split it as per type

I have a array object with mixed type of key values. i need to separate it with type of key value pair.

JavaScript

I need to split it the above object separately as per type. as like below

Array Object 1

JavaScript

Array Object 2

JavaScript

As like above. I need to achieve it by java script. I have tried it with forEach condition. but i am not achieve the result. Thanks in Advance.

Advertisement

Answer

First, you need to be able to check if the object is of type A or type B.

For instance :

JavaScript

Here, I decided to check the existence of the property TOOL_PM or TOOL_PM_x. But it’s a business decision that you have to make.

Then, you iterate thought the array, check the current object and put it in the right output array :

JavaScript

When you reach a programming issue, break it into simpler things. Rewriting your issue with other inputs sometimes helps to resolve it.

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