String Manipulation in JavaScript Flashcards
.length()
returns count of total number of characters
.charAt()
returns a char at the given index number
.includes()
returns True if the string includes a certain character/word, False if it doesnt
.indexOf()
displays index of the first occurence of the element. if the element is not in a string, it will return -1
.replace()
returns a string replacing all the old char or CharSequence to newchar or ChrSequence. The original string will remain unchanged
.search()
seraches a string for a specified value, and returns the position of the match
.slice()
str.slice(2,5)
will print out up to index 5 but not including it (“I love Javascript”//”lov”)
.split()
splits a string into an array of substrings, and returns the new array. Delimeter can be a space or any character and JS will look for that inside the string and split:
let str = "I love Javascript" let a = str.split(" ") console.log(a)// [ 'I', 'love', 'Javascript' ]
.toUpperCase()
returns the calling string value converted to upper case
.concat()
adds the strings
.join()
transforms array to a string, it is opposite of split()
.trim()
removes whitespaces from the both sides of the string