简体   繁体   中英

multiple values from cookie to var in angular

My code looks like:

  var ietms = $cookies.get('items');

I can get values back, however there are multiples such as:

Testvalue1|Testvalue2|testvalue3

I want to be able to split the three items lets say into multiple vars, like:

var ietms = $cookies.get('items')[0];
var ietms2 = $cookies.get('items')[1];
var ietms3 = $cookies.get('items')[2];

But simply split the value based on the '|'separating the values

If the returned data is a string, you can use var splitItems = ietms.split('|') to create one array consisting of the individual values. But its hard to say if this applies to your question, because the return type of testvalue1|..|.. is unclear

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