首页 > 其他分享 >无涯教程-String.prototype.includes(searchString, position = 0)函数

无涯教程-String.prototype.includes(searchString, position = 0)函数

时间:2024-02-02 19:31:56浏览次数:20  
标签:searchString console String 无涯 includes str 字符串 prototype

该方法确定字符串是否是给定字符串的子字符串。

String.prototype.includes - 语法

str.includes(searchString[, position])
  • searchString - 要搜索的子字符串。

  • position        - 该字符串中开始搜索searchString的位置;默认为0。

String.prototype.includes - 返回值

true 如果字符串包含子字符串;否则为 false 。

String.prototype.includes - 示例

var str='Hello World';  

console.log(str.includes('hell'))     
console.log(str.includes('Hell'));  

console.log(str.includes('or'));   
console.log(str.includes('or',1))

运行上面代码输出

false 
true 
true 
true 

参考链接

https://www.learnfk.com/es6/es6-string-method-includes.html

标签:searchString,console,String,无涯,includes,str,字符串,prototype
From: https://blog.51cto.com/u_14033984/9561245

相关文章

  • 无涯教程-String.prototype.startsWith(searchString, position = 0)函数
    该方法确定字符串是否以指定的字符开头。String.prototype.startsWith-语法str.startsWith(searchString[,position])searchString  - 在此字符串开头要搜索的字符。position     - 该字符串中开始搜索searchString的位置;默认为0。String.prototype.s......
  • 无涯教程-toString()函数
    此方法返回表示指定对象的字符串。toString()-语法string.toString()toString()-返回值返回表示指定对象的字符串。toString()-示例varstr="Applesareround,andApplesareJuicy.";console.log(str.toString());运行上面代码输出Applesareround,an......
  • 无涯教程-toLowerCase()函数
    此方法返回转换为小写的调用字符串值。toLowerCase()-语法string.toLowerCase()toLowerCase()-返回值返回转换为小写的调用字符串值。toLowerCase()-示例varstr="Applesareround,andApplesareJuicy.";console.log(str.toLowerCase())运行上面代码输......
  • 无涯教程-substring()函数
    此方法返回String对象的子集。substring()-语法string.substring(indexA,[indexB])indexA   - 小于字符串长度的0到1之间的整数。indexB   - (可选)0到字符串长度之间的整数。substring()-返回值substring方法根据给定的参数返回新的子字符......
  • 无涯教程-substr()函数
    此方法以指定的字符数返回从指定位置开始的字符串中的字符。substr()-语法string.substr(start[,length]);start   -开始提取字符的位置(0到1的整数,小于字符串的长度)。length  -要提取的字符数substr()-返回值substr()方法根据给定的参数返回新的子字符......
  • 无涯教程-split()函数
    此方法通过将字符串对象分成子字符串来将字符串对象拆分为字符串数组。split()-语法string.split([separator][,limit]);separator  - 指定用于分隔字符串的字符。limit      - 整数,用于指定要找到的分割数的限制。split()-返回值split方法返回......
  • 无涯教程-slice()函数
    此方法提取字符串的一部分并返回新的字符串。slice()-语法string.slice(beginslice[,endSlice]);beginSlice  - 从零开始的索引。endSlice   - 终止提取的从零开始的索引。如果省略,则slice提取到字符串的末尾。slice()-返回值如果成功,slice返......
  • 无涯教程-lastIndexOf()函数
    此方法返回最后一次出现的指定值的调用字符对象内的索引,如果没有找到该值,则从fromIndex或-1开始搜索。lastIndexOf()-语法string.lastIndexOf(searchValue[,fromIndex])searchValue  - 表示要搜索的值的字符串。fromIndex   - 调用字符串中开始搜索的位......
  • 无涯教程-concat()函数
    此方法添加两个或多个字符串,并返回一个新的单个字符串。concat()-语法string.concat(string2,string3[,...,stringN]);string2...stringN  - 这些是要串联的字符串。concat()-返回值返回单个串联的字符串。concat()-示例varstr1=newString("Thisis......
  • 无涯教程-constructor函数
    构造函数返回对创建原型的字符串函数的引用。constructor-语法string.constructorconstructor-返回值返回创建该对象的函数。varstr=newString("Thisisstring");console.log("str.constructoris:"+str.constructor)运行上面代码输出str.constructoris:fun......