Skip to content

Buzzingz

Unleashing the Power of Code

  • HTML
  • CSS
  • JavaScript
  • Toggle search form

JavaScript String Methods

Posted on April 2, 2023April 2, 2023 By shani No Comments on JavaScript String Methods

In JavaScript, there are several built-in methods for manipulating strings. Here are some commonly used ones:

  1. length: returns the length of the string
let str = 'Hello, World!';
console.log(str.length); // Outputs: 13
  1. toUpperCase(): converts the string to uppercase
let str = 'Hello, World!';
console.log(str.toUpperCase()); // Outputs: HELLO, WORLD!
  1. toLowerCase(): converts the string to lowercase
let str = 'Hello, World!';
console.log(str.toLowerCase()); // Outputs: hello, world!
  1. indexOf(): returns the index of the first occurrence of a specified substring
let str = 'Hello, World!';
console.log(str.indexOf('o')); // Outputs: 4
  1. substring(): returns a substring of the string
let str = 'Hello, World!';
console.log(str.substring(0, 5)); // Outputs: Hello
  1. replace(): replaces a specified substring with another string
let str = 'Hello, World!';
console.log(str.replace('World', 'Universe')); // Outputs: Hello, Universe!
7.split(): splits a string into an array of substrings
let str = 'Hello, World!';
console.log(str.split(',')); // Outputs: ['Hello', ' World!']
  1. trim(): removes whitespace from the beginning and end of a string
let str = '   Hello, World!   ';
console.log(str.trim()); // Outputs: Hello, World!
9.charAt(): returns the character at a specified index
let str = 'Hello, World!';
console.log(str.charAt(4)); // Outputs: o
  1. endsWith(): checks if a string ends with a specified substring
let str = 'Hello, World!';
console.log(str.endsWith('!')); // Outputs: true
  1. startsWith(): checks if a string starts with a specified substring
let str = 'Hello, World!';
console.log(str.startsWith('Hello')); // Outputs: true
12.includes(): checks if a string contains a specified substring
let str = 'Hello, World!';
console.log(str.includes('World')); // Outputs: true

String manipulation is a common task in web development, and understanding string methods is essential for working with strings effectively in JavaScript. The above methods are just a few examples of the many built-in string methods available in JavaScript.

Javascript

Post navigation

Previous Post: JavaScript String Search
Next Post: JavaScript Template Literals

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JavaScript Tutorial

  • JavaScript Tutorial
  • JavaScript Where To
  • JavaScript Output
  • JavaScript Statements
  • JavaScript Syntax
  • JavaScript Comments
  • JavaScript Variables
  • JavaScript Let
  • JavaScript Const
  • JavaScript Operators
  • JavaScript Arithmetic
  • JavaScript Assignment
  • JavaScript Data Types
  • JavaScript Functions
  • JavaScript Objects
  • JavaScript Events
  • JavaScript Strings
  • JavaScript String Methods
  • JavaScript String Search
  • JavaScript Template Literals
  • JavaScript Numbers
  • JavaScript BigInt
  • JavaScript Number Methods
  • JavaScript Number Properties
  • JavaScript Arrays
  • JavaScript Array Methods
  • JavaScript Sorting Arrays
  • JavaScript Array Iteration
  • JavaScript Array Const
  • JavaScript Date Objects
  • JavaScript Date Formats
  • JavaScript Get Date Methods
  • JavaScript Set Date Methods
  • JavaScript Math Object
  • JavaScript Random
  • JavaScript Booleans
  • JavaScript Comparison and Logical Operators
  • JavaScript if, else, and else if
  • JavaScript Switch Statement
  • JavaScript For Loop
  • JavaScript For In
  • JavaScript For Of
  • JavaScript While Loop
  • JavaScript Break and Continue
  • JavaScript Iterables
  • JavaScript Sets
  • JavaScript Maps
  • JavaScript typeof
  • JavaScript Type Conversion
  • JavaScript Bitwise Operations
  • JavaScript Regular Expressions
  • JavaScript Operator Precedence
  • JavaScript Errors
  • JavaScript Scope
  • JavaScript Hoisting: Understanding the Basics
  • JavaScript Use Strict: The Importance of Strict Mode in JavaScript
  • The JavaScript this Keyword
  • JavaScript Arrow Function: A Concise and Comprehensive Guide
  • JavaScript Classes: Understanding the Basics
  • JavaScript Modules
  • JavaScript JSON
  • JavaScript Debugging
  • JavaScript Style Guide
  • JavaScript Best Practices
  • JavaScript Common Mistakes: How to Avoid Them
  • JavaScript Performance: Techniques for Improving Your Code
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions

Copyright © 2023 Buzzingz.

Powered by PressBook WordPress theme