,
Use the method spliceto split a string into two parts. string.length-3will contain the last three characters, where it string.slice(0, string.length-3)will return the first characters n-3, starting from the beginning of the line. Use the array.joinmethod to combine fragments.
function insertSpace(string){
var output = [string.slice(0, string.length-3),' ', string.slice(string.length-3)].join('');
return output
}
console.log(insertSpace('A1233AD'))
Demo
source
share