简体   繁体   中英

Get text between 2nd and 3rd delimiter in a string - Java script

I have a string like this - tom|harry|john|elizabeth|hopkin|wayne

I would like to extract the value john and wayne from this string and store in variables. How can I do that in jquery or javascript?

If you know which "index" john and wayne is, you can use split() to make it an array and get it from an array with index.

var str = "tom|harry|john|elizabeth|hopkin|wayne"
var arr = str.split("|");
var third = arr[2],
    last = arr[arr.length-1];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM