DEV Community

mmvergara
mmvergara

Posted on • Updated on

Javascript Tagalog - String includes Method

Ano ngaba ang String includes method sa Javascript?
Try ko explain ng madalian,
For example yung string ko is "Hello", may o sa "Hello" diba? so "Hello".includes('o') == true
yung includes method returns niya is a Boolean Value (true or false)

Pano gamitin:
First Argument - yung string na gusto mo i search if included siya sa original string.

const x = 'Hello World'

console.log( x.includes('foo') ) //false 

console.log( x.includes('Hello') ) // true

console.log( x.includes('World') ) // true

//Case Sensitive
console.log( x.includes('world') ) // false

//Hindi naapektuhan yung original String
console.log( x ) // 'Hello World'
Enter fullscreen mode Exit fullscreen mode

Second Argument (optional, default is 0) - kung sang index ng string siya mag-uumpisa mag search.

//Searching sa 'Hello World
console.log( x.includes('Hello',0) ) // false

//Searching sa 'ello World
console.log( x.includes('Hello',1) ) // false

//Searching sa 'llo World
console.log( x.includes('llo',2) ) // true

Enter fullscreen mode Exit fullscreen mode

Workaround para maging case insensitive

const a = 'Hello World'
const b = 'WoRlD'

const x = a.toLowerCase()
const y = b.toLowerCase()
console.log(x.includes(y)) // true

// Shorter Version
console.log( a.toLowerCase().includes( b.toLowerCase() ) ) //true

Enter fullscreen mode Exit fullscreen mode

convert niyo muna yung dalawang string sa lowercase or uppercase bago i pag-kumpara.


More tagalog Javascript Learning Resources:
https://javascript-methods-in-tagalog.vercel.app/

Top comments (0)