Jquery make array on the fly using the value of a variable

Hi,

I run the following code

var pagePath = "http://www.xxx.com/multimedialist.txt";
$j('#textLoader').load(pagePath, function (responseText) {
var multimediaListContents = responseText;
});

Open in new window


so now i have a variable which has the exact contents of my multimedialist.txt file:
var multimediaListContents = "unipol,2EksseaXwbQ|altaformazione,u8lpELxse5M"

Open in new window


I would like to use jquery to create two arrays on the fly as follows:

var videoIconName = [];
videoIconName[ 0 ] = "unipol";
videoIconName[ 1 ] = "altaformazione";

var videoLocation = [];
videoLocation[ 0 ] = "2EksseaXwbQ";
videoLocation[ 1 ] = "u8lpELxse5M";

Open in new window



How could I achieve this?

Thanks in advance!
badwolfffAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
dont really need to use jQuery, straight up JavaScript is pretty simple:

var tmpArr = multimediaListContents.Split( '|' );
var videoIconName = tmpArr[0].Split( ',' )
var videoLocation = tmpArr[1].Split( ',' )

Open in new window

0
badwolfffAuthor Commented:
Hi,

thanks for the message.
I tried your code and I get a wrong output.
What I get is this:

videoIconName[0] = "unipol";
videoIconName[1] = "2EksseaXwbQ";

and

videoLocation[0] = "altaformazione";
videoLocation[1] = u8lpELxse5M";


Since the txt file contained this string:
unipol,2EksseaXwbQ|altaformazione,u8lpELxse5M


what i need is as follows:

videoIconName[ 0 ] = "unipol";
videoIconName[ 1 ] = "altaformazione";

videoLocation[ 0 ] = "2EksseaXwbQ";
videoLocation[ 1 ] = "u8lpELxse5M";



Also I used the jQuery loop to ensure that the two arrays got all the right content from the txt file. If I don't use the array and there are 20 sets of values present in the, txt then I would need to do them manually.

thanks again
0
Chris StanyonWebDevCommented:
Assuming you can use the pipe and comma for the delimiters, then something like this:

var pagePath = "http://www.xxx.com/multimedialist.txt";

$('#textLoader').load(pagePath, function (responseText) {
	var multimediaListContents = responseText.split("|");
	var videoIconName = new Array();
	var videoLocation = new Array();
	
	$(multimediaListContents).each(function(i,elem) {
		var temp = elem.split(",");
		videoIconName.push(temp[0]);
		videoLocation.push(temp[1]);
	});
	
	console.log(videoIconName);
	console.log(videoLocation);
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
badwolfffAuthor Commented:
Thanks ChrisStanyon!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.