03、ES6 字符串扩展
来源:互联网 发布:.net b2b商城源码 编辑:程序博客网 时间:2024/06/05 21:53
1.拼接字符串: 用反引号声明 拼接变量的方式 ${变量名}
let num = 1;
let str1 = `${num}`;
console.log(str1);
1)可以执行运算
let str2 = `${num+10}`;
console.log(str2);
2)换行可以直接换
let str3 = `${num+100}
ok`;
console.log(str3);
运行结果:
2.字符串的查找
1)includes() 如果存在 返回true 或 false
let str = 'hello chongqing';
console.log(str.includes('c'));
console.log(str.includes('2'));
2)startsWith 查找是否在头部 返回true 或 false
let str = 'hello chongqing';
console.log(str.startsWith('h'));
console.log(str.startsWith('2'));
3)endsWith 查找是否在尾部 返回true 或 false
let str = 'hello chongqing';
console.log(str.endsWith('ng'));
console.log(str.endsWith('hl'));
4)repeat(10) 复制几遍
let str = 'hello chongqing !';
console.log(str.repeat(1));
console.log(str.repeat(3));
console.log(str.repeat(5));
5)正则表达式匹配扩展
let str = 'aaa_aa_a';
let r1 = /a+/g;
/*
* 从上次匹配的地方开始匹配 的
* 第一次: aaa 剩余的部分 _aa_a
* 第二次 _aa_a 开始匹配
* */
console.log(r1.exec(str));
console.log(r1.exec(str));
console.log('**************************************');
let r2 = /a+/y;
console.log(r2.exec(str));
console.log(r2.exec(str));
- 03、ES6 字符串扩展
- 【ES6】字符串的扩展
- ES6-字符串扩展
- 【es6】字符串的扩展
- ES6字符串扩展
- ES6字符串扩展
- ES6字符串扩展
- ES6--字符串的扩展
- es6语法-字符串扩展
- ES6 字符串扩展
- ES6-字符串扩展-Unicode
- ES6-字符串扩展-repeat()
- es6字符串的扩展
- ES6-字符串扩展-模板字符串
- es6 chapter4 字符串的扩展
- ES6学习笔记-字符串扩展
- es6学习--字符串的扩展
- ES6(三) 字符串的扩展
- linux,对根目录进行扩充(lvm)
- react-native tab标签
- 皇后问题 搜索
- ubuntu下查看特定程序所占用的网络端口号
- Method,SEL,IMP
- 03、ES6 字符串扩展
- C++作业5
- 数据结构之单链表的冒泡排序
- Ubuntu 16.04下Apache2+php7以及Nginx+php7迷醉记录
- jQuery对象转成DOM对象
- 爬取广州天气数据和数据可视化
- C++作业5
- xListView的简单使用
- 二十五、UI-Grid 导出数据