模板字符串和标签模板

const getCourseList = function() {
// ajax
return {
status: true,
msg: '获取成功',
data: [{
id: 1,
title: 'Vue 入门',
date: 'xxxx-01-09'
}, {
id: 2,
title: 'ES6 入门',
date: 'xxxx-01-10'
}, {
id: 3,
title: 'React入门',
date: 'xxxx-01-11'
}]
}
}; const { data: listData, status, msg } = getCourseList(); function foo(val) {
return val.replace('xxxx', '2020');
} if (status) {
let arr = []; listData.forEach(function({ date, title }) { arr.push(
`
<li>
<span>${ `课程名: ${ title }` }</span>
<span>${ foo(date) }</span>
</li>
`
); }); let ul = document.createElement('ul');
ul.innerHTML = arr.join(''); document.body.appendChild(ul); } else {
alert(msg);
}

padStart padEnd

    {
let str = 'i';
// 插入在5的位置
let str1 = str.padStart(5, 'mooc');
console.log(str1);
// 倒序插入在5的位置
let str2 = str.padEnd(5, 'mooc');
console.log(str2);
}

repeat

    {
function repeat(str, num) {
return new Array(num + 1).join(str);
}
console.log(repeat('s', 3));
}

startsWith endsWith

    {
const str = 'A promise is a promsie'; console.log(str.startsWith('B'));
console.log(str.startsWith('A pro')); console.log(str.endsWith('promsie'));
console.log(str.endsWith('A'));
}

includes

    {
const str = 'A promise is a promise';
if (~str.indexOf('promise')) {
console.log('存在"promise"');
} if (str.includes('a promise')) {
console.log('存在"a promise"');
}
}

字符串转数组+遍历

    let str = 'PROMISE';
// 四种方法:转成数组后遍历
var oStr = Array.prototype.slice.call(str);
var oStr = str.split('');
const oStr = [...str];
const [...oStr] = str;
console.log(oStr);
//单个字符输出
oStr.forEach(function(word) {
console.log(word);
});

对全是英文的字符串中的大写字符加密 A -> 100  B -> 99

    const map = {A: '100', B: '99', C: '98', D: '97', E: '96', F: '95', G: '94', H: '93', I: '92', J: '91', K: '90', L: '89', M: '88', N: '87', O: '86', P: '85', Q: '84', R: '83', S: '82', T: '81', U: '80', V: '79',W: '78',X: '77',Y: '76', Z: '75'};
const words = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; oStr.forEach(function(word, index) {
if (words.includes(word)) oStr[index] = map[word];
});
console.log(oStr.join(''));

使用for-of遍历字符串

    let str = 'PROMISE';
let newStr = '';
const map = {A: '100', B: '99', C: '98', D: '97', E: '96', F: '95', G: '94', H: '93', I: '92', J: '91', K: '90', L: '89', M: '88', N: '87', O: '86', P: '85', Q: '84', R: '83', S: '82', T: '81', U: '80', V: '79',W: '78',X: '77',Y: '76', Z: '75'};
for (let word of str) {
if (str.includes(word)) newStr += map[word];
}
console.log(newStr);

Unicode是一项标准,包括字符集、编码方案等
解决传统的字符编码方案的局限

最新文章

  1. 实现文字自动横移--- jquery尺寸相关函数
  2. 移动Web开发调研
  3. linux下ubuntu系统安装及开发环境配置
  4. Java-note-输入流
  5. javascript权威指南学习笔记1
  6. C语言 &#183; 区间K大数查询
  7. MySQL DATE_FORMAT
  8. 读Zepto源码之Event模块
  9. [转载] java多线程总结(二)
  10. Vue.js简单记录
  11. Understanding Flash: Blocks, Pages and Program / Erases
  12. Spark学习之路 (十八)SparkSQL简单使用
  13. WordCount系统分析与设计作业
  14. 李洪强iOS开发之静态库的打包一
  15. iOS:App 内部更改使用语言/ 重定义系统的宏
  16. 【C#/WPF】图片的切割/切图/裁剪图片
  17. TW实习日记:第五天
  18. 框架----Django框架(基础篇)
  19. 基于腾讯云centos简单搭建VSFTP
  20. GUN C中的socket学习(一)

热门文章

  1. HDU 1005 Number Sequence(矩阵快速幂,快速幂模板)
  2. (四)mybatis逆向工程
  3. javascript 对象api
  4. ansible实现SSH配置免密互信
  5. Java TreeSet的使用
  6. 《自拍教程6》打开Windows文件后缀
  7. helm 错误the server has asked for the client to provide credentials
  8. Java自学-多线程 常见线程方法
  9. 0x01 C语言-编写第一个hello world
  10. dotMemory 2019.3.1一直试用