zoukankan      html  css  js  c++  java
  • es6字符串扩展(+模板字符串拼接)

    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);
  • 相关阅读:
    复利计算--结对1.0,做汉堡,结对2.0
    复利计算1.0,2.0,3.0,4.0,5.0
    2020助教总结
    作业2
    作业一
    linux设置opengl版本
    第一次个人作业
    寒假助教总结
    直播
    2020面向对象程序设计寒假作业3
  • 原文地址:https://www.cnblogs.com/ll15888/p/11195618.html
Copyright © 2011-2022 走看看