How to search for multiple variables within javascript file and concat? -
here code;
function concatvar(data) { (var data in window) { if (window[data]== data.match(data+(/\[[0-9]+\]/))) return data; } } var data1 = [{ x: 290, y: 160}, {x: 391, y: 160}, {x: 391, y: 160}] var data2 = [{x: 200, y: 160}, {x: 193, y: 160}, {x: 421, y: 260}] var data3 = [{x: 200, y: 160}, {x: 193, y: 160}, {x: 421, y: 260}] var data = data1.concat(data2, data3) concatvar();
i able search through javascript file , find variable named data[+numbers] , concat them 1 variable.
i'm struggling find way done? , i'm not sure if using loop within window advisable?
any advice appreciated!
cheers
the regex should use more /var\s+data\d+\s+=\s*[\w\w]+;/ig
(which attempt match variables ones provided). i'd personally try replace not match , use regex extract actual assigned values after doing splitting treat them 1 @ time: oneofthosematchedvariables.replace(/data\d+\s+=\s*/i, '')
.
oneofthosematchedvariables
should string looking "var data1 = [{ x: 290, y: 160}, {x: 391, y: 160}, {x: 391, y: 160}];"
this assuming parsed whole file needed , have stored execute on it.
Comments
Post a Comment