I have this variable:
var myVar = "r.object.subobject.variable";
I want to add each of the "levels" of this string to an array. My array will contain:
"r.object"
"r.object.subobject"
"r.object.subobject.variable"
I know that I can use the split () JavaScript function with RegEx, but the one I have returns a whole string. For example, I try:
var myArray = myVar.split(/r[.].+/);
Thus, it myArray[0]always appears as "r.object.subobject.variable".
How can I do myArray[0] = "r.object", myArray[1] = "r.object.subobject"and myArray[2] = "r.object.subobject.variable"?
I hope I just don’t understand how regular expressions work, instead of doing some far-fetched recursion or concatenation of the array, dividing only into periods.
Additional restrictions and reference information
- 1 , , .
r. ( while, , .) - , .
- , - , . ( , , AS3, .)