今天遇到这个问题,发现ぜんぜんわすねまます
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(test.substring()); //llo world
console.log(test); //hello world
//---1个整数传参返回结果一样,亦不会影响原来的字符串
console.log(test.slice(-)); //ld
console.log(test); //hello world
console.log(test.substr(-)); //ld
console.log(test); //hello world
console.log(test.substring(-)); //hello world
console.log(test); //hello world
// //---1个负数传参不会影响原来的字符串
// //str.slice(a); str.substr(a);返回结果为字符串从右往左两位
// //而 str.substring();则返回字符串本身 //均两位参数测试
console.log(test.slice(,)); //o w
console.log(test); //hello world
console.log(test.substr(,)); //o world
console.log(test); //hello world
console.log(test.substring(,)); //o w
// console.log(test); //hello world
//第2位传参为正整数
//1.都不会改变原有str的长度
//2.str.slice(a,b); str.substring(a,b);
//均为下标0起,由下标a到下标b截取的值
// str.substr(a,b); //与前两个方法有区别
//获得结果为截取下标0起,由下标a起往后b位下标 console.log(test.slice(,-)); //o wo
console.log(test); //hello world
console.log(test.substr(,-)); // (空)
console.log(test); //hello world
console.log(test.substring(,-)); //hell
console.log(test); //hello world
//第2位传参为负整数
//1.都不会改变原有str的长度
//2.test.slice(a,b); 获得为下标0起,由下标a起往后b位下标截取(下标0起,即-3为下标4)
// test.substr(a,b); 返回为空
// test.substring(a,b); 获得为下标0起,由下标a起往前b位下标截取(下标0起,即-3为下标4)

最新文章

  1. Eclipse自动生成UML图(转载)
  2. chrome内核浏览器缓存资源找回方法
  3. Mysql数据库的索引原理
  4. C# Json处理日期和Table
  5. Objective-c 类接口 (@interface) (类定义)
  6. form验证及图片上传
  7. J.U.C并发框架
  8. bit 和 byte
  9. 如何在Ubuntu 16.04上安装PythonGDAL 2.1?
  10. pagerank 数学基础
  11. 软件安装配置笔记(三)——ArcGIS系列产品安装与配置(补档)(附数据库连接及数据导入)
  12. std::lock_guard/std::unique_lock
  13. 背水一战 Windows 10 (65) - 控件(WebView): 对 WebView 中的内容截图, 通过 Share Contract 分享 WebView 中的被选中的内容
  14. css position[转
  15. 修改oracle为归档模式
  16. Maven中groupId和artifactId的含义
  17. Cesium简介 [转]
  18. DataSet转换成List<>
  19. Java 处理cookie的方法
  20. 使用dockerfile 创建ubuntu ssh镜像

热门文章

  1. Dubbo简介与基本概念
  2. Support URL
  3. git 常用操作汇总
  4. HttpRunner学习1--Windows&Linux安装httprunner
  5. Java题库——Chapter16 JavaFX UI组件和多媒体
  6. Linux - CentOS 7 安装 .Net Core 运行环境
  7. 3.Python常用逻辑运算符
  8. Java实现抢红包功能
  9. 微信小程序模板(template)和组件的区别
  10. C lang:Pointer and multidimensional array