arrays - Is it possible to grab the NUMBER that was concatenated to a string? (Javascript) -
i'm using cookies , setting them this:
document.cookie ="cookievalue1="+cookievalue1; document.cookie ="cookievalue2="+cookievalue2; document.cookie ="cookievalue3="+cookievalue3;
then put in array called cookie array:
var allcookies = document.cookie; cookiearray = allcookies.split(';');
if print out array, like: cookievalue1= 23 or cookievalue2= 42.
but there way value after string (23 or 42 only) rather string , number?
i tried deleting "cookievalue=" part, makes can't store cookies. i'm using forms , want numbers inputted can use them , add/subtract them on page. right now, can't add or subtract anything.
you do:
allcookies.split(';').map(c => c.split('=')[1]);
it'd give cookie value string. if numbers can do:
allcookies.split(';').map(c => +c.split('=')[1]);
this gives cookie values numbers.
Comments
Post a Comment