js 字符串的截取,主要有三个函数,一般使用三个函数:substr,substring,slice. 而这三个函数是不完全一样的,平时很难记住,在这里做下笔记,下次遇到的时候,直接从这里参考,调用合适的方法: 从参数方面考量:当有一个参数(正数)的时候,这三个函数基本上没有基本上没有什么区别 1. 有一个参数(正数): <script> var str = "abcdefghijklmnopqrstuvwxyz"; var a = str.slice(2); var b =…
今天遇到这个问题,发现ぜんぜんわすねまます3个方法,直接上代码吧,[网络版本较多就不注明参考过哪些了 -0- ] var test = 'hello world'; //均一位参数测试 console.log(test.slice()); //llo world console.log(test); //hello world console.log(test.substr()); //llo world console.log(test); //hello world console.log(…
万恶的输入法,在sublime中会显示出繁体字,各位看官见谅. 1.slice()方法:该方法在数组和string对象中都拥有. var a = [1,2,3,4,5,6]; var s = 'this is a string'; console.log(a.slice(1,3));//結果為 [2,3]; console.log(a.slice(-1);//結果為6; console.log(s.slice(1,3));//結果為 hi; console.log(s);//結果為 this i…