Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

JavaScript TRIM

by suresh

The JavaScript TRIM function is a String function used to remove the empty spaces from both the Right-hand side and Left-hand side of a string. The syntax of the string Trim function in JavaScript Programming Language is

String_Object.trim()

JavaScript TRIM Function Example

The following set of examples will help you understand how to use a string trim function to trim extra spaces.

<!DOCTYPE html>
<html>
<head>
    <title> TRIM JavaScript </title>
</head>
<body>
    <h1> JavaScript TRIM </h1>
<script>
    var Str1 = "    Tutorial Gateway     ";
    var Str2 = Str1.trim();
    var Str3 = "    Tutorial Gateway".trim();
    var Str4 = "Tutorial Gateway     ".trim();
    var Str5 = " \t   Tutorial Gateway    \n ".trim();
 
    document.write(Str2 + "<br \>");
    document.write(Str3 + "<br \>");
    document.write(Str4 + "<br \>");
    document.write(Str5 + "<br \>");
</script>
</body>
</html>
JavaScript TRIM Function

First we declared the String variable Str1 and assigned corresponding value using following statement

var Str1 = "    Tutorial Gateway     ";

It removes the white spaces from both the Left & Right side of String variable Str1 using the trim function

var Str2 = Str1.trim();

Trimming only left-hand side of a string using JavaScript Trim function. It removes white spaces from the left-hand side

var Str3 = "    Tutorial Gateway".trim();

Trimming the Right-hand side of string using the Trim String Function. The following statement removes white spaces from the right-hand side

var Str4 = "Tutorial Gateway     ".trim();

Next, we used the line terminator along with string objects. If you observe the above screenshot, Trim function is trimming the terminators like \t and \n

var Str5 = " \t   Tutorial Gateway    \n ".trim();

Placed Under: JavaScript

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy