loading...

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

gautamraju15 profile image ray_v101 ・1 min read

This is the array that i tried working with :

let array = [
"getX",
"getY",
"getZ",
"getRotationX",
"getRotationY",
"getRotationZ",
"getRotation"];

I tried different ways , but coudn't acheieve so , I want to arrange analogus valuegetx, gety, getz into one subarray, same goes for rotation and scale. Does anyone have idea on how to proceed ?

output: const array = [['getY','getX','getZ'], ['getPositionX'....],...];

Discussion

markdown guide
 

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)

 
 

thankyou so much kim :)