DEV Community

mmvergara
mmvergara

Posted on • Edited on

2 1

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/

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay