includes()
判斷字符串中是否包含指定的字串(有的話返回true,否則返回false)
console.log('hello world'.includes('world' , 7)); //參數一:匹配的字串;參數二:從第幾個開始匹配
startsWith() 判斷字符串是否以特定的字串開始
endsWith() 判斷字符串是否以特定的字串結束
let url = 'admin/index.php'; console.log(url.startsWith('admin')); //返回true console.log(url.endsWith('php')); //返回true
模板字符串拼接
原始的:
let tag = '<div><span>'+obj.username+'</span><span>'+obj.age+'</span><span>'+obj.gender+'</span></div>';
console.log(tag);
高級的:
// 用反引號表示模板,模板中的內容可以有格式,通過${}方式填充數據 let fn = function(info){ return info; } let tpl = ` <div> <span>${obj.username}</span> <span>${obj.age}</span> <span>${obj.gender}</span> <span>${1+1}</span> <span>${fn('nihao')}</span> </div> `; console.log(tpl);