Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
Convert string into date using JavaScript
Next article icon

String in DSA Using JavaScript

Last Updated : 09 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A string in JavaScript is a sequence of characters enclosed in single (‘), double (“), or backticks (`). Strings in JavaScript are immutable, meaning their contents cannot be changed after creation. Any operation that modifies a string actually creates a new string.

Example:

JavaScript
let s = "GfG"; console.log(s[0]); console.log(s.length);  

Output
G 3 

Common String Methods in JavaScript:

  • length – Returns the number of characters in a string.
  • charAt(index) – Returns the character at the specified index.
  • slice(start, end) – Extracts a section of a string and returns it as a new string.
  • substring(start, end) – Similar to slice(), but does not accept negative indices.
  • toUpperCase() / toLowerCase() – Converts the string to uppercase or lowercase.
  • trim() – Removes whitespace from both ends of a string.
  • replace(searchValue, newValue) – Replaces a specified value with another value in a string.
  • split(separator) – Splits a string into an array based on a specified separator.
  • includes(substring) – Checks if a string contains a given substring, returning true or false.
  • concat(str1, str2, …) – Joins two or more strings together.
  • Please refer JavaScript String Methods for more methods.

Easy Problems Problem On String using JavaScript

  1. Reverse a String
  2. Palindrome Check
  3. Check for Subsequence
  4. Check Anagram
  5. Reverse Words
  6. Isomorphic Strings 
  7. Check Pangram or not

Medium Problems On String in JavaScript

  1. Implement Atoi
  2. Validate an IP address
  3. Find the largest word in dictionary
  4. Equal 0, 1, and 2
  5. Longest Palindromic Subsequence
  6. Longest substring without Repeating

Hard Problems On String in JavaScript

  1. Search Pattern (KMP-Algorithm)
  2. Search Pattern (Rabin-Karp Algorithm)
  3. Shortest Common Supersequence
  4. Number of words with K maximum distinct vowels
  5. Longest substring to form a Palindrome
  6. Longest Valid Parenthesis


Next Article
Convert string into date using JavaScript

A

aayushmohansinha
Improve
Article Tags :
  • JavaScript
  • Technical Scripter
  • Web Technologies
  • JavaScript-DSA
  • javascript-string
  • Technical Scripter 2022

Similar Reads

  • Convert string into date using JavaScript
    In this article, we will convert a string into a date using JavaScript. A string must follow the pattern so that it can be converted into a date. A string can be converted into a date in JavaScript through the following ways: Table of Content Using JavaScript Date() constructorUsing JavaScript toDat
    3 min read
  • JavaScript - String Strip
    Here are the different methods to Strip String in JavaScript Using trim() Method (Most Common)The trim() method removes whitespace from both ends of a string. This is the most commonly used to strip whitespace in JavaScript. [GFGTABS] JavaScript const s1 = " Hello, World! "; const s2 = s1.
    2 min read
  • How to Print a String in JavaScript ?
    In JavaScript, printing a string means displaying the contents of a string variable or literal to the console, webpage, or any other output medium. Strings are a fundamental data type in JavaScript, representing sequences of characters enclosed within single ('') or double ("") quotes. Table of Cont
    2 min read
  • Reverse a String in JavaScript
    We have given an input string and the task is to reverse the input string in JavaScript. Using split(), reverse() and join() MethodsThe split() method divides the string into an array of characters, reverse() reverses the array, and join() combines the reversed characters into a new string, effectiv
    1 min read
  • JavaScript String substring() Method
    The substring() method in JavaScript is used to extract characters between two indices from a string, without modifying the original string. This method returns a new string that is a part of the original string, starting from a specified position up to (but not including) another specified position
    5 min read
  • JavaScript String Formatting
    JavaScript string formatting refers to the technique of inserting variables, expressions, or values into strings to make them dynamic and readable. It can be done using methods like concatenation, template literals (backticks), and custom formatting functions, which help create flexible and clean st
    5 min read
  • Random String Generator using JavaScript
    JavaScript is a lightweight, cross-platform, interpreted scripting language. It is well-known for the development of web pages, many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side developments. In this article, we need to create a Ran
    7 min read
  • JavaScript - Escape a String
    These are the following ways to Escape a String in JavaScript: 1. Using BackslashesThe most straightforward way to escape characters is by using backslashes (\). This method allows you to include special characters like quotes (" or '), backslashes, and control characters within a string. [GFGTABS]
    1 min read
  • How to modify a string in JavaScript ?
    JavaScript strings are used for storing and manipulating text. It can contain zero or more characters within quotes and its indexing starts with 0. Strings are defined as an array of characters. In Javascript, we can also convert strings to a Character array.  Representing a String:  1. Using double
    3 min read
  • JavaScript String toString() Method
    The toString() method in JavaScript converts a string object to a string primitive. It returns a string representing the specified object. This method is automatically called when a string object needs to be defined as a text value or concatenated with another string. The toString() method also conv
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences