2025年01月12日 建站教程
includes()
方法主要用于判断字符串是否包含指定的子字符串。下面web建站小编给大家简单介绍一下使用方法!
数组中使用include方法判断是否存在元素
var arr = ["dog", "cat", "pig"]; console.log("输出结果1:",arr.includes("cat")) //输出结果1: true console.log("输出结果2:",arr.includes("house")) //输出结果2: false
字符串中使用include方法判断是否存在元素
var str = "hellow world"; console.log('输出结果1:', str.includes("web")) //输出结果1: false console.log('输出结果2:', str.includes("hellow")) //输出结果2: true
本文链接:http://so.lmcjl.com/news/21200/