Answers for "remove suffix string js"

0

remove suffix string js

let text = 'ABCD';

// replace the last two characters with empty string
let result1 = text.replace(/.{0,2}$/, '');

// remove the last two characters
let result2 = text.slice(0, -2);

// remove the last two characters
let result3 = text.substring(0, text.length - 2);

console.log(result1);  // AB
console.log(result2);  // AB
console.log(result3);  // AB
Posted by: Guest on April-04-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language