script 1
let text1 = "an example string";let length = text1.length;
document.getElementById('output1').innerHTML = length;
the built-in length property returns the length of a string
strLen = string.length;
the slice method extracts part of a string and returns the extracted part in a new string. the end position is not included.
newStr = text.slice(startPosition, endPosition);
substring is similar to slice, except that the start and end values less than 0 are treated as 0 in substring
let newStr = str.substring(startPosition, endPosition);
the split method splits a string into an array of substrings, then returns the new array and not the original string.
the strings can be split by " " blank space, "," commas, or "|" pipes.
const myArray = str.split(" ");
the replace method replaces a specified value with another value in a string
the replace method will change only the first match. use replaceAll to replace all matches.
let newStr = str.replace("removeStr", "replaceStr");
the trim method can remove all the extra white space from a string
let newStr = oldStr.trim();
converts the entire string to upper case
let newStr = oldStr.toUpperCase();
this method returns the character at a specified index in a string.
let char = str.charAt(indexPosition);