I am wondering if there's a way to use the str.includes() function in JavaScript, but check at a certain index of the string, without changing the original string. For example:
var str = "this is a test";
str.includes("test"); //returns true
str.includes("test", 0) //returns false, as "test" is not at position 0
str.includes("test", 10) //returns true, as "test" is at position 10 in the string
I've been trying to find a way to do this, but haven't been able to figure it out. Could somebody please help me?
str.indexOf("test") === 0or=== 10?trueregardless of what number I put as the second argument.indexOf(),lastIndexOf(), ormatchAll()may be more helpful for whatever your use case is.str.slice(10).startsWith('test')?