DEV Community

Discussion on: is there anyway to submit analogus array values into sub-array?

Collapse
 
dance2die profile image
Sung M. Kim

If your JS environment support Array#flatMap, you can do a simple regex match.

[array.flatMap(f => f.match(/get[XYZ]/g)).filter(Boolean), 
 array.flatMap(f => f.match(/getRotation[XYZ]/g)).filter(Boolean)]

demo

If not, then you'd have to flat the result of regex's match value (as .match returns an array of values)

Collapse
 
gautamraju15 profile image
ray_v101

thankyou :)

Collapse
 
dance2die profile image
Sung M. Kim

You're welcome~