I have stored a dynamically created object as a string in a database because I lack knowledge of better choices and at this point I think there is no going back. I am trying to parse this is in a way so the user can not break it somehow.
I output a string that is in format
|attr1|,subA,subB,subNth,~,|attrNth|,sub2A,sub2B,sub2C,sub2D,~
1st then split it by doing
supertest = option.split("~");
Leaving me with
|attr1|,subA,subB,subNth,,,|attrNth|,sub2A,sub2B,sub2C,sub2D,,
2nd I loop through find my pipe symbols, and split again
for(n=0; n<supertest.length; n++) {
var start_pos = supertest[n].indexOf('|') + 1;
var end_pos = supertest[n].indexOf('|',start_pos);
var optionParsed = supertest[n].substring(start_pos,end_pos);
test = supertest[n].split("|").pop();
choiceArray = test.split(",");
}
Leaving me with 3 arrays with dynamically created names(I only want two)
array1- ,subA,subB,subNth,
array2- ,sub2A,sub2B,sub2C,sub2D,
array3- blank or null or undefined?
JSFIDDLE: http://jsfiddle.net/SteveRobertson/4YHSr/21/
I am ultimately trying to create dynamic select input lists with "attr"'s as labels and "subNths" as options. so I tried to create a jsfiddle to make it easier, because i now realize this is a bigger question than i initially thought, but for some reason after the three select drop down lists are done loading everything disappears. I tried. If anyone can help me I would appreciate it. What I ideally want to know is how can i get my individual arrays to be in the format
attr1 = [subA, subB, subNth]
Thank you for anyone who thinks they might know this and can help
var xkcd = { author: 'Randall Munroe', urls: ['http://xkcd.com', 'http://m.xkcd.com'], updated: ['Monday', 'Wednesday', 'Friday'] }, xkcdToJSON = JSON.stringify(xkcd); console.log(xkcdToJSON);more-legible JS Fiddle demo (outputs:'{"author":"Randall Munroe","urls":["http://xkcd.com","http://m.xkcd.com"],"updated":["Monday","Wednesday","Friday"]}').