startsWith() endsWith() in Javascript 🔥

Pubblicato il: 25 febbraio 2024
sul canale di: RoadsideCoder
4,594
259

In JavaScript, the startsWith() and endsWith() methods are used to check whether a string starts or ends with a specific substring, respectively. These methods return a boolean value (true or false) based on whether the condition is met or not.

Here's how they work:

startsWith(): This method checks if a string starts with the characters of a specified string.

const str = 'Hello World';
console.log(str.startsWith('Hello')); // true
console.log(str.startsWith('He')); // true
console.log(str.startsWith('hello')); // false (case-sensitive)

endsWith(): This method checks if a string ends with the characters of a specified string.

const str = 'Hello World';
console.log(str.endsWith('World')); // true
console.log(str.endsWith('rld')); // true
console.log(str.endsWith('world')); // false (case-sensitive)


In questa pagina del sito puoi guardare il video online startsWith() endsWith() in Javascript 🔥 della durata di ore minuti seconda in buona qualità , che l'utente ha caricato RoadsideCoder 25 febbraio 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 4,594 volte e gli è piaciuto 259 spettatori. Buona visione!