var name="james mark";
var name="james " ;
so how to trim both the names occur any condition from this anytime in javascript
Output:
james mark
james
var name="james mark";
var name="james " ;
so how to trim both the names occur any condition from this anytime in javascript
Output:
james mark
james
You can replace all instances of repeated white space with a single space and also trim all leading and trailing white space:
name.replace(/\s+/g,' ');
name.replace(/^\s+|\s+$/g,''); // or use .trim()
for more information you should read the description on the .replace()
and .trim()
functions on MDN
Try with:
var name="james mark";
var j = names.split(' ');
alert(j[0]);
//The otput: James (without the blank spaces)