SIGN IN SIGN UP

Login to your account

Username or Email *
Password *
Remember Me
LWC Progress | ( Lessons)

Lesson: 02 | String Methods


toUpperCase(): Converts a string to uppercase.


toLowerCase(): Converts a string to lowercase.


length: Returns the number of characters in a string.


charAt(index): Returns the character at the specified index in a string.

let str = 'Hello';
console.log(str.charAt(0));  // Output: H

concat(str1, str2, ...): Concatenates two or more strings together.

let str1 = 'Hello';
let str2 = 'World';
console.log(str1.concat(', ', str2));  // Output: Hello, World

indexOf(substring): Returns the index of the first occurrence of a specified substring within a string. Returns -1 if the substring is not found.

let str = 'Hello, world!';
console.log(str.indexOf('world'));  // Output: 7

substring(startIndex, endIndex): Extracts a portion of a string starting from the startIndex and up to, but not including, the endIndex.

let str = 'Hello, world!';
console.log(str.substring(7, 12));  // Output: world

split(separator): Splits a string into an array of substrings based on a specified separator.

let str = 'apple,banana,orange';
console.log(str.split(','));  // Output: ["apple", "banana", "orange"]

trim(): Removes whitespace (spaces, tabs, or newlines) from the beginning and end of a string.

let str = '   Hello, world!   ';
console.log(str.trim());  // Output: Hello, world!

These are just a few examples of the many string methods available in JavaScript. String methods allow you to perform various operations such as manipulating, searching, extracting, and transforming strings to suit your needs.


Prev You need to login to have access to the quizzes. Next

Mastered by 12 users.

Lightning Web Components

A. Component Reference (27 lessons)
B. Lightning Web Components | Utilities (11 lessons)
C. Lightning Web Component Guide (41 lessons)
D. Java Script Methods for LWC (23 lessons)
E. HTML (18 lessons)
Go to top