0% found this document useful (0 votes)
20 views1 page

JavaScript String Methods Cheat Sheet

Uploaded by

pooja Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

JavaScript String Methods Cheat Sheet

Uploaded by

pooja Patil
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript String Methods - One Page Compact Cheat Sheet

Quick compact reference with syntax, use, and example.


Method Syntax Use Example
at() [Link](i) Char at i, supports negatives"abc".at(-1) // "c"

charAt() [Link](i) Char at position "abc".charAt(1) // "b"

includes() [Link](sub) Check substring "hello".includes("he") // true

indexOf() [Link](val) Find index "abcabc".indexOf("b") // 1

lastIndexOf() [Link](val) Find last index "abcabc".lastIndexOf("b") // 4

slice() [Link](a,b) Substring extract "abcdef".slice(1,4) // "bcd"

substring() [Link](a,b) Substring extract "abcdef".substring(2,5) // "cde"

split() [Link](sep) Split string "a,b,c".split(",") // ["a","b","c"]

replace() [Link](x,y) Replace first match "hi hi".replace("hi","hey") // "hey hi"

replaceAll() [Link](x,y) Replace all "hi hi".replaceAll("hi","hey") // "hey hey"

trim() [Link]() Remove whitespace " hi ".trim() // "hi"

padStart() [Link](n,ch) Pad left "5".padStart(3,"0") // "005"

padEnd() [Link](n,ch) Pad right "5".padEnd(3,"0") // "500"

toUpperCase() [Link]() Uppercase "hi".toUpperCase() // "HI"

toLowerCase() [Link]() Lowercase "HI".toLowerCase() // "hi"

startsWith() [Link](sub) Check prefix "[Link]".startsWith("file") // true

endsWith() [Link](sub) Check suffix "[Link]".endsWith(".txt") // true

repeat() [Link](n) Repeat "ab".repeat(3) // "ababab"

You might also like