References

String.includes()

Leírás

let x = 'Javascript'
 
console.log(x.includes('ipt', 4))
// Expected output: false

A 4 indextől kezdve az "ipt" szöveget tartalmazz az adott karakterláncot.

console.log(x.includes('ipt'))
// Expected output: true

Szintaxis

includes(searchString)
includes(searchString, position)

Példa

const sentence = 'The quick brown fox jumps over the lazy dog.'
const word = 'fox'
 
console.log(`The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence`)
// Expected output: "The word "fox" is in the sentence"
in this article
back to top