lines[i].trim(); does NOT modify the current string (see the doc here). It returns a new string.

If you want to trim the current string, then you need to do this:

lines[i] = lines[i].trim();
Answer from jfriend00 on Stack Overflow
🌐
SheCodes
shecodes.io › athena › 6815-why-isn-t-my-trim-working-in-my-code
[JavaScript] - Why isn't my trim() working in my code? - | SheCodes
Learn why the trim() function may not working in your code and what you may need to do to fix it. ... arithmetic operators JavaScript addition subtraction multiplication division modulus programming coding basics
Discussions

jquery - javascript trim() doesn't work - Stack Overflow
i'm trying to trim down a string before removing parts of it, but there's something off about the spaces in the string. the string i'm trying to trim is this 200 KristianMedK ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - Why is the trim() method not working but instead breaking my function? - Stack Overflow
It's not only that it doesn't do what it's supposed to, but it seems there's an error in my use of the method here, as it breaks the function. I got this copy-attribution javascript function off the web. It works perfectly per se, but I need to add double quotes at the beginning and end of the copied selection, so I need to add a trim... More on stackoverflow.com
🌐 stackoverflow.com
internet explorer - .trim() in JavaScript not working in IE - Stack Overflow
I tried to apply .trim() to a string in one of my JavaScript programs. It's working fine under Mozilla, but an error displays when I try it in IE8. Does anyone know what is going on here? Is there More on stackoverflow.com
🌐 stackoverflow.com
.trim() in JavaScript not working in IE8
There was an error while loading. Please reload this page More on github.com
🌐 github.com
4
March 11, 2014
🌐
Acrobatusers
answers.acrobatusers.com › Why-doesn-trim-function-work-q284274.aspx
Why doesn't the .trim() function work? (JavaScript)
String.trim() is not supported in Acrobat's JavaScript. You will have to come up with a different method to trim whitespace at the beginning or the end of a string.
🌐
jQuery
api.jquery.com › jQuery.trim
jQuery.trim() | jQuery API Documentation
Note: This API has been deprecated in jQuery 3.5; please use the native String.prototype.trim method instead. Unlike jQuery.trim, String.prototype.trim does not work with types other than strings (null, undefined, Number).
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-typeerror-trim-is-not-a-function
TypeError: trim is not a function in JavaScript [Solved] | bobbyhadz
The "TypeError: trim is not a function" error occurs when we call the trim() method on a value that is not a string.
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › jsref_trim_string.asp
JavaScript String trim() Method
The trim() method does not change the original string. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
GitHub
github.com › angular-translate › angular-translate › issues › 437
.trim() in JavaScript not working in IE8 · Issue #437 · angular-translate/angular-translate
March 11, 2014 - .trim() in JavaScript not working in IE8#437 · Copy link · Labels · bugbug-fix · llyys · opened · on Mar 11, 2014 · Issue body actions · //quick fix would be to add this on top of angular-translate.js · if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } } Reactions are currently unavailable ·
Author   angular-translate
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-trim-method-d53972004e23
Basics of Javascript · String · trim() (method) | by Jakub Korch | Nerd For Tech | Medium
June 28, 2021 - The last case to cover is using trim on “null”, “undefined” or other special objects. If you try to do so, you will get a TypeError. Which makes sense, since there is nothing to trim there.
🌐
SitePoint
sitepoint.com › javascript
Trim() function in Chrome not working - JavaScript - SitePoint Forums | Web Development & Design Community
June 29, 2011 - My trim() function seems to halt JavaScript execution in Chrome. Why is this? function trim(s) { s = s.replace(/(^\\s*)|(\\s*$)/gi,""); s = s.replace(/[ ]{2,}/gi," "); s = s.replace(/\ /,"\ "); return s; } It works in IE and firefox… wait no it doesn’t. not anymore. wtf.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › trim
String.prototype.trim() - JavaScript - MDN Web Docs
const greeting = " Hello world! "; console.log(greeting); // Expected output: " Hello world! "; console.log(greeting.trim()); // Expected output: "Hello world!";
🌐
Edureka
edureka.co › blog › javascript-trim
JavaScript trim | JavaScript String Trim Method | Edureka
February 10, 2025 - So let us move on with this JavaScript Trim article and see the following function, This removes the space present both at front and back i.e leading and trailing whitespaces. ... Hi,Welcome to Edureka! Note: Trim never removes the spaces in between. It only trims leading and trailing whitespaces.
🌐
SamanthaMing
samanthaming.com › tidbits › 85-string-trim
How to Trim String in JavaScript | SamanthaMing.com
Remember trim only works for whitespace at the start and end. So it doesn't trim the space in between words. ... Same with multi-line, it only trims the beginning of the first word and the ending of the last word. const multiLine = ` hi there ...
🌐
Nativescript
discourse.nativescript.org › javascript
Trim function not working in javascript - JavaScript - NativeScript Community Forum
August 1, 2018 - This code works, var phoneNumber = signupVM.get("signupVal").phone; but this doesn’t var phoneNumber = trim(signupVM.get("signupVal").phone); I have to remove whitespaces which some keyboards adds by default. ... Please go through the basics of JavaScript, trim is not a global function but a method in a string instance.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-string-prototype-trim-function
JavaScript String trim() Method - GeeksforGeeks
April 1, 2023 - JavaScript str.trimLeft(): The str.trimLeft() method is used to remove the white spaces from the start of the given string. It does not affect the trailing white spaces. ... Example 1: In this example, the extra space is placed on the right side of the string the trimLeft() function will work in this case.
🌐
Quora
quora.com › Why-is-Node-js-trim-not-a-function-JavaScript-node-js-trim-development
Why is Node.js trim() not a function (JavaScript, node.js, trim, development)? - Quora
Answer: The trim() function is a string function of Node.js which is used to remove white spaces from the string. Syntax: [code]string.trim() [/code]Parameter: This function does not accepts any parameter. Return Value: The function returns the string without white spaces. Below programs demo...