How to slice string from the end in JavaScript? | javascript substring to end
YouhavetousenegativeindexinString.prototype.slice()function.usingnegativeindexasfirstargumentreturnstheslicedstringtothe6elementscountingfromtheendofthestring.varexample="javascript"; console.log(example.slice(-6));usingnegativeindexasthesecondargumentreturnstheslicedstringfrom0tothe6thelementcountingfromtheend.Itsoppositetothefirstmethod.varexample="javascript"; console.log(example.slice(0,-6));Inyourparticularcase,youhavetousethesecondmethod.console.log(11001000000000000001010...
You have to use negative index in String.prototype.slice() function.
using negative index as first argument returns the sliced string to the 6 elements counting from the end of the string. var example = "javascript"; console.log(example.slice(-6)); using negative index as the second argument returns the sliced string from 0 to the 6th element counting from the end. Its opposite to the first method. var example = "javascript"; console.log(example.slice(0, -6));In your particular case, you have to use the second method.
console.log(11001000000000000001010.slice(0, -18)); console.log(110000000001101011100.slice(0, -18));If you want to read more about that function, visit: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice[1]
References https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice (developer.mozilla.org)