×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to convert delimited string to an array of array names

How to convert delimited string to an array of array names

How to convert delimited string to an array of array names

(OP)
Hi all,

Trying to figure out how to force .concat to recognize a delimited string as an array of array names.

I have an external file that contains many arrays and I want to be able to dynamically choose which arrays via tree checkboxes (named the same as the array names)

Some of the following is from a GUI library...but the issue is native JavaScript so hopefully it will be ok to read.

I am trying to figure out how to get a comma delimited string to be recognized as an array of array names so I can parse via library methods

I am not familiar with what terms so code is really the only way to let most understand what I am trying to do.

Please see in blue highlighted text in code block...this works but it's hard coded...I need it to be dynamic (variable) of array names are collected from checkboxes which creates a delimited string and pass it as a parameter in the .concat. I thought about loop and eval but was hoping not to have to go that way.

The flow is a user selects items in a tree...this info is collected in a delimited string..this string needs to be recognized as an array of arrays as seen in blue which works....then populates a grid

Definitely open to suggestions...thanks!


CODE --> javascript

U_13_HTS = [
		     ["LCK","50 FF","A-000001","1909","1230000010","00000001","Smith","2019"]
                   ]

	U_215_GP = [
		     ["LCK","501 GS","A-000002","1909","1230000011","00000002","Walker","2019"],
                     ["LCK","501 GS","A-000002","1909","1230000011","00000002","Walker","2019"]
                   ]


	U_15_GP = [
		    ["RDT","542 AT","A-000003","1909","1230000013","00000002","Johnson","2019"],
                    ["RDT","542 AT","A-000004","1909","1230000014","00000002","Johnson","2020"]
                  ]


        str = "U_13_HTS,U_215_GP,U_15_GP" // hard coded for example

  	data = [].concat.apply([], [str]); 			   //str data does not work
  	data = [].concat.apply([], [eval(str)]); 		   //eval str gets last array (U_15_GP)  
 	data = [].concat.apply([], [U_13_HTS,U_215_GP,U_15_GP]); //hard coded delimited array names works   

 	myGrid_SDC.parse(data,"jsarray"); 

RE: How to convert delimited string to an array of array names

Hi

The brackets ( [] ) should be inside the eval() not outside :

CODE --> JavaScript

data = [].concat.apply([], eval('[' + str + ']')) 

Feherke.
feherke.github.io

RE: How to convert delimited string to an array of array names

(OP)
SMH on bracket displacement...lol...thanks that was exactly what I needed!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close