26 November 2024
Lesson 5 Async JavaScript | Promise | String Methods
Event Loop
Video: Event Loop in JavaScript
Promises
Async JavaScript
Article for just look through: async javascript
JavaScript string methods
-
charAt(index)- Returns the character at the specified index.- Example:
"hello".charAt(1); // "e"
- Example:
-
concat(...strings)- Combines the original string with one or more strings and returns the result.- Example:
"hello".concat(" ", "world"); // "hello world"
- Example:
-
includes(substring, start)- Checks if a string contains a specified substring, starting at an optional position.- Example:
"hello world".includes("world"); // true
- Example:
-
indexOf(substring, start)- Returns the index of the first occurrence of a substring, or-1if not found.- Example:
"hello world".indexOf("o"); // 4
- Example:
-
lastIndexOf(substring, start)- Returns the index of the last occurrence of a substring, or-1if not found.- Example:
"hello world".lastIndexOf("o"); // 7
- Example:
-
slice(start, end)- Extracts a section of the string and returns it as a new string.- Example:
"hello world".slice(0, 5); // "hello"
- Example:
-
substring(start, end)- Returns the part of the string between the start and end indices.- Example:
"hello world".substring(0, 5); // "hello"
- Example:
-
toLowerCase()- Converts the string to lowercase.- Example:
"Hello World".toLowerCase(); // "hello world"
- Example:
-
toUpperCase()- Converts the string to uppercase.- Example:
"Hello World".toUpperCase(); // "HELLO WORLD"
- Example:
-
trim()- Removes whitespace from both ends of the string.- Example:
" hello world ".trim(); // "hello world"
- Example:
-
split(separator, limit)- Splits a string into an array of substrings based on a separator.- Example:
"hello world".split(" "); // ["hello", "world"]
- Example:
-
replace(searchValue, newValue)- Replaces occurrences of a substring with a new string.- Example:
"hello world".replace("world", "everyone"); // "hello everyone"
- Example:
-
replaceAll(searchValue, newValue)- Replaces all occurrences of a substring with a new string.- Example:
"hello world world".replaceAll("world", "everyone"); // "hello everyone everyone"
- Example:
-
startsWith(substring, start)- Checks if the string starts with the specified substring.- Example:
"hello world".startsWith("hello"); // true
- Example:
-
endsWith(substring, length)- Checks if the string ends with the specified substring.- Example:
"hello world".endsWith("world"); // true
- Example:
-
repeat(count)- Repeats the string the specified number of times.- Example:
"hello".repeat(3); // "hellohellohello"
- Example:
-
padStart(targetLength, padString)- Pads the string at the start with the specified string until it reaches the target length.- Example:
"5".padStart(3, "0"); // "005"
- Example:
-
padEnd(targetLength, padString)- Pads the string at the end with the specified string until it reaches the target length.- Example:
"5".padEnd(3, "0"); // "500"
- Example: