If you need to support IE 8, you can use replace() with a regular expression instead: code example
Example: If you need to support IE 8, you can use replace() with a regular expression instead:
var str = " Hello World! ";
alert(str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''));