I have a string, 12345.00, and I would like it to return 12345.0.
12345.00
12345.0
I have looked at trim, but it looks like it is only trimming whitespace and slice which I don't see how this would work. Any suggestions?
trim
slice
You can use the substring function:
let str = "12345.00"; str = str.substring(0, str.length - 1); console.log(str);
This is the accepted answer, but as per the conversations below, the slice syntax is much clearer:
let str = "12345.00"; str = str.slice(0, -1); console.log(str);
I have the following array. var arr = [1,0,2]; I would like to remove the last element i.e. 2. I used arr.slice(-1); but it doesn't remove the value.
In order to duplicate an array in JavaScript: which of the following is faster to use? ###Slice method var dup_array = original_array.slice(); ###For loop for(var i = 0, len = original_array.length; i < len; ++i) dup_array[i] = …
Does anyone know what the difference is between these two methods? String.prototype.slice String.prototype.substring