views:

261

answers:

1

Hi,

is it possible to get the last value of an string, that looks like this for example:

tm="1610612741|Bulls|Chicago|CHI"

and save it as a variable?

Something like that:

var tm = $(this).find('htm').attr('tm');

I only need the "CHI" string. I tried everything, but what i found doesnt work. I get the string and the var from an xml file. Also is it possible to parse the xml from a "live" version, like http://www.exampledomain.com/test.xml?

Appreciate your help!

Nicole

A: 
var tm = '1610612741|Bulls|Chicago|CHI';
var arr = tm.split('|');
var lastPart = arr[arr.length - 1];

alert(lastPart); // CHI
Simeon
wow thank you, it works perfectly. almost what i got, but i guess i got confused, still learning :) thank you!
Great! Please mark my solution as the answer if that is the case.
Simeon