How do we replace last character of a string?
SetCookie('pre_checkbox', "111111111111 11 ")
checkbox_data1 = GetCookie('pre_checkbox');
if(checkbox_data1[checkbox_data1.length-1]==" "){
checkbox_data1[checkbox_data1.length-1]= '1';
console.log(checkbox_data1+"after");
}
out put on console : 111111111111 11 after
Last character was not replaced by '1' dont know why
also tried : checkbox_data1=checkbox_data1.replace(checkbox_data1.charAt(checkbox_data1.length-1), "1");
could some one pls help me out
str += something), as pass-by-value languages like JS won't let the callee just up and change the caller's variables.+to create a string with additional chars, then yes. You can assign it to the variable/property that held the original, and it looks changed. But for example,str[0] = 'x'will not work; it just silently fails, as a string's indexes are not writable. It has to be done another way.