References
String.endsWith()
Leírás
A példa eredménye true
, mivel a "text" változót "World" szóra végződik.
const text = 'Hello World'
console.log(text.endsWith('World'))
// Expected output: true
A példa eredménye true
, mivel a "example" változót első 20 karaktere "Lexicon" szóra végződik.
const example = 'My Javascript Lexicon'
console.log(example.endsWith('Lexicon', 20))
// Expected output: true
A hossz megmondja, milyen hosszú szövegben kell keresni.
Adott szöveg megtalálható-e egy szöveg végén.
Szintaxis
endsWith(searchString)
endsWith(searchString, endPosition)
Példa
const str1 = 'Cats are the best!'
console.log(str1.endsWith('best!'))
// Expected output: true
console.log(str1.endsWith('best', 17))
// Expected output: true
const str2 = 'Is this a question?'
console.log(str2.endsWith('question'))
// Expected output: false