Beginner Friendly · Hands-on · Free

trims the white space from the left and right side of the string

trim() function இங்கு நாம் கொடுக்கும் string இல் starting மற்றும் ending இல் ஏதுனும் whitespaces இருந்தால் அதனை remove செய்கிறது

5 min read Updated Dec 13, 2025

trim() Function in Javascript

trim() function இங்கு நாம் கொடுக்கும் string இல் starting மற்றும் ending இல் ஏதுனும் whitespaces இருந்தால் அதனை remove செய்கிறது.

str.trim()

Note: trim() function இங்கு string இன் ஆரம்பம் மற்றும் இறுதியில் ஏதுனும் whitespaces இருந்தால் அதனை remove செய்கிறது. இந்த function whitespaces மட்டுமே remove செய்கிறது ஆனால் original string இல் எந்த மாற்றமும் செய்யாது. இது மிகவும் முக்கியமான function ஆகும்.

Example1

<script>
var input = "   Success is a journey not a destination   ";
var res = input.trim();
document.writeln(res);
</script>

மேலே உள்ள Example1-ஐ கவனிக்கவும் இங்கு input என்ற variable இல் " Success is a journey not a destination " என்ற string value ஆனது store செய்யபட்டுள்ளது. இங்கு நன்றாக கவனிக்கவும் string இன் ஆரம்பம் மற்றும் இறுதியில் whitespaces கள் உள்ளன. input.trim() function இருபுறமும் உள்ள whitespaces ஐ remove செய்து Success is a journey not a destination என்ற output ஐ கொடுக்கிறது.

Output:

Success is a journey not a destination

Example2

<script>
var data = "Success only comes to those who dare to attempt   ";
var res = data.trim();
document.writeln(res);
</script>

மேலே உள்ள Example2-ஐ கவனிக்கவும் இங்கு data என்ற variable இல் "Success only comes to those who dare to attempt " என்ற string value ஆனது store செய்யபட்டுள்ளது. இங்கு data.trim() என்ற function பயன்படுத்தபடுகிறது, இங்கு string இன் வலது புறத்தில் whitespaces கள் உள்ளன. data.trim() function இந்த whitespaces ஐ remove செய்து Success only comes to those who dare to attempt என்ற output ஐ கொடுக்கிறது.

Output:

Success only comes to those who dare to attempt

இது பற்றிய தங்களின் கருத்துகளை இங்கே பதிவிடுங்கள் . இது பயனுள்ளதாக விரும்பினால் மற்றவர்களுக்கும் இதை share செய்யுங்கள்.