DEV Community

mmvergara
mmvergara

Posted on • Edited on

3 1

Javascript Tagalog - String charAt Method

Ano ngaba ang String charAt method sa Javascript?
Pano gamitin:
First Argument - bigay mo yung index (number) tapos re return niya yung character na nasa index nayon

const x = 'Hello'

console.log( x.charAt(0) ) // H
console.log( x.charAt(1) ) // e
console.log( x.charAt(2) ) // l
console.log( x.charAt(3) ) // l
console.log( x.charAt(4) ) // o

// di naapektuhan yung original string
console.log( x ) // Hello
Enter fullscreen mode Exit fullscreen mode

Notice from: Frank Wisniewski
"this only works as long as the strings do not contain unicode characters"
so pag may emoji or unicode characters gumamit nalang ng match method


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

Top comments (3)

Collapse
 
frankwisniewski profile image
Frank Wisniewski

this only works as long as the strings do not contain unicode characters

const x = 'H🍺llo'

console.log( x.charAt(0) ) // H
console.log( x.charAt(1) ) // �
console.log( x.charAt(2) ) // �
console.log( x.charAt(3) ) // l
console.log( x.charAt(4) ) // l

// di naapektuhan yung original string
console.log( x ) // H🍺llo

const chars = 'H🍺llo'.match(/./ug);
console.log(chars[0]); //H
console.log(chars[1]); //🍺
console.log(chars[2]); //l
console.log(chars[3]); //l
console.log(chars[4]); //o
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mmvergara profile image
mmvergara

Ohh I see, that's very insightful, I'll edit the all the string-related blogs to become aware of this, Thank you so much! <3

Collapse
 
vexuzdorotan profile image
Jonnel Salvador "VeXuZ" Dorotan

Ayos ang iyong article, co-Filipino dev! :)

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay