Javascript Code Function to Remove All Sorts of Spaces
Javascript Code Function to Remove All Sorts of Spaces, Trim, Remove Spaces, Remove Multiple Spaces
Home
Short:
function funcSpacesCleaned(data, btrim = false, bremove_spaces = false, bremove_double_spaces = false){ let bspacesfound = false; // SEE IF THERE ARE ANY SPACES if(data.indexOf(' ') != -1){ bspacesfound = true; }else{ return [bspacesfound, data]; } ////////////////////////////////////////////////////////// // IF WE ARE HERE IT MEANS THERE ARE SPACES IN [$data] // ///////////////////////////////////////////////////////// if(btrim){ // TRIM data = data.trim(); } if(bremove_spaces){ // REMOVE SPACES data = data.replace(/ /g, ''); } if(bremove_double_spaces){ // REMOVE DOUBLE SPACES while(data.indexOf(' ') != -1){ data = data.replace(/ /g, ' '); } } return [bspacesfound, data]; }
source code home