字符串截取
看到一道前端的面试题
对string对象经行扩展,使其具有删除前后空格的方法;
1 <script type="text/javascript"> 2 String.prototype.delempty = function(){ 3 var str = this; 4 while(str[0] == " ") 5 { 6 str = str.substring(1); 7 } 8 9 while(str[str.length-1] == " ") 10 { 11 str = str.substring(0,str.length-1); 12 } 13 return str; 14 15 } 16 </script>