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:
JavaScript - How to Match Multiple Parts of a String Using RegExp?
Next article icon

How to process each letter of text using JavaScript ?

Last Updated : 16 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Given a string and the task is to process it character by character. 

  • JavaScript String toUpperCase() Method: This method converts a string to uppercase letters. 
    Syntax: 
string.toUpperCase()
  • Parameters: This method accepts single parameter str which is required. It specifies the string to be searched.
    Return Value: It returns a string denoting the value of a string converted to uppercase. 
     
  • JavaScript String charAt() Method: This method returns the character at the passed index in a string. The index of characters starts from 0.
    Syntax: 
string.charAt(index)
  • Parameters: This method accepts single parameter index which is required. It specifies the integer representing the index of the character to return.
    Return Value: It returns a string, denoting the character at the passed index, or an empty string if the index number is invalid. 
     

Example 1: This example processes the string letter by letter using for loop and converts each letter to uppercase separately. 

html




<!DOCTYPE HTML>
<html>
    <head>
        <title>
            How to process each character of text
        </title>
    </head>
     
    <body style = "text-align:center;">
     
        <h1 style = "color:green;" >
            GeeksForGeeks
        </h1>
     
        <p id = "GFG_UP" style =
            "font-size: 15px; font-weight: bold;">
        </p>
 
         
        <button onclick = "gfg_Run()">
            check
        </button>
         
        <p id = "GFG_DOWN" style =
            "color:green; font-size: 20px; font-weight: bold;">
        </p>
 
         
        <script>
            var el_up = document.getElementById("GFG_UP");
            var el_down = document.getElementById("GFG_DOWN");
            var str = "This is String";
            el_up.innerHTML = "String = '"+str + "'";
         
            function gfg_Run() {
                var str_Upper = "";
                for (var i = 0; i < str.length; i++) {
                    str_Upper += str.charAt(i).toUpperCase();
                }
                el_down.innerHTML = str_Upper;
            }        
        </script>
    </body>
</html>                   
 
 

Output: 

  • Before clicking on the button: 

  • After clicking on the button: 

Example 2: This example processes the string letter by letter using for in loop and alerts each letter separately. 

html




<!DOCTYPE HTML>
<html>
    <head>
        <title>
            How to process each letter of text
        </title>
    </head>
     
    <body style = "text-align:center;">
     
        <h1 style = "color:green;" >
            GeeksForGeeks
        </h1>
     
        <p id = "GFG_UP" style =
            "font-size: 15px; font-weight: bold;">
        </p>
 
         
        <button onclick = "gfg_Run()">
            check
        </button>
         
        <script>
            var el_up = document.getElementById("GFG_UP");
            var str = "str";
            el_up.innerHTML = "String = '" + str + "'";
         
            function gfg_Run() {
                for (var i in str) {
                    alert(" character = "+str.charAt(i));
                }
            }        
        </script>
    </body>
</html>                   
 
 

Output: 

  • Before clicking on the button: 

  • After clicking on the button: 



Next Article
JavaScript - How to Match Multiple Parts of a String Using RegExp?

P

PranchalKatiyar
Improve
Article Tags :
  • JavaScript
  • Web Technologies

Similar Reads

  • How to read a local text file using JavaScript?
    Reading a local text file involves accessing the contents of a file stored on a user's device. Using JavaScript, this can be achieved with the HTML5 File API and the FileReader object, which reads files selected through an <input> element or drag-and-drop, asynchronously. Getting Started with
    4 min read
  • How to Detect Keypress using JavaScript ?
    In this article, keyboard detection is performed using HTML and CSS. HTML stands for "Hypertext Markup Language". HTML language helps the developer to create and design web page elements like links, sections, paragraphs, headings, and blockquotes for web applications. CSS stands for "Cascading Style
    2 min read
  • How to break nested for loop using JavaScript?
    The break statement, which is used to exit a loop early. A label can be used with a break to control the flow more precisely. A label is simply an identifier followed by a colon(:) that is applied to a statement or a block of code. Note: there should not be any other statement in between a label nam
    3 min read
  • JavaScript - How to Match Multiple Parts of a String Using RegExp?
    In JavaScript, the regular expression (RegExp) object provides a powerful mechanism to search, match, and manipulate strings. One of the common use cases is matching multiple parts of a string that satisfy a certain pattern. You can easily do this using global (g) and other RegExp features. 1. Using
    3 min read
  • How to Remove Spaces From a String using JavaScript?
    These are the following ways to remove space from the given string: 1. Using string.split() and array.join() MethodsJavaScript string.split() method is used to split a string into multiple sub-strings and return them in the form of an array. The join() method is used to join an array of strings usin
    2 min read
  • JavaScript - How to Make First Letter of a String Uppercase?
    Here are the different approaches to make the first letter of a string uppercase in JavaScript. 1. Using charAt() with slice() Method (Most Common)The combination of charAt() and slice() is the simplest and widely used way to capitalize the first letter of a string. [GFGTABS] JavaScript const s1 =
    2 min read
  • How to find out which Character Key is Pressed using JavaScript?
    To find which key is pressed in JavaScript, use event listeners like keydown, keypress, or keyup. By accessing properties such as event.key or event.code, it becomes easy to identify the specific key pressed. This approach is useful for handling user input and triggering actions based on key events.
    2 min read
  • How to Change Text Inside all HTML Tags using JavaScript ?
    In this article, we will learn how to change the text content inside all HTML tags using JavaScript. This skill is valuable when you need to dynamically modify the text displayed on a web page. which can be useful for various scenarios like updating content, internationalization, or creating dynamic
    3 min read
  • How to Get Character of Specific Position using JavaScript ?
    Get the Character of a Specific Position Using JavaScript We have different approaches, In this article we are going to learn how to Get the Character of a Specific Position using JavaScript Below are the methods to get the character at a specific position using JavaScript: Table of Content Method 1
    4 min read
  • How to replace lowercase letters with an other character in JavaScript ?
    Given a string and the task is to replace all lowercase letters from a string with the other characters in JavaScript. There are some approaches to replace the character that are described below: JavaScript replace() Method: This method searches a string for a defined value, or a regular expression,
    2 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