String.prototype.trimStart() - JavaScript | MDN Skip to main content Skip to search MDN HTML HTML: Markup language HTML reference Elements Global attributes Attributes See all… HTML guides Responsive images HTML cheatsheet Date & time formats See all… Markup languages SVG MathML XML CSS CSS: Styling language CSS reference Properties Selectors At-rules Values See all… CSS guides Box model Animations Flexbox Colors See all… Layout cookbook Column layouts Centering an element Card component See all… JavaScriptJS JavaScript: Scripting language JS reference Standard built-in objects Expressions & operators Statements & declarations Functions See all… JS guides Control flow & error handing Loops and iteration Working with objects Using classes See all… Web APIs Web APIs: Programming interfaces Web API reference File system API Fetch API Geolocation API HTML DOM API Push API Service worker API See all… Web API guides Using the Web animation API Using the Fetch API Working with the History API Using the Web speech API Using web workers All All web technology Technologies Accessibility HTTP URI Web extensions WebAssembly WebDriver See all… Topics Media Performance Privacy Security Progressive web apps Learn Learn web development Frontend developer course Getting started modules Core modules MDN Curriculum Check out the video course from Scrimba, our partner Learn HTML Structuring content with HTML module Learn CSS CSS styling basics module CSS layout module Learn JavaScript Dynamic scripting with JavaScript module Tools Discover our tools Playground HTTP Observatory Border-image generator Border-radius generator Box-shadow generator Color format converter Color mixer Shape generator About Get to know MDN better About MDN Advertise with us Community MDN on GitHub Blog Toggle sidebar Tecnologia Web para desenvolvedores JavaScript Referência JavaScript Objetos Globais String String.prototype.trimStart() Theme OS default Light Dark Português (do Brasil) Remember language Learn more Deutsch English (US) Français 日本語 한국어 Português (do Brasil) Русский 中文 (简体) Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs. View in English Always switch to English String.prototype.trimStart() Baseline Widely available This feature is well established and works across many devices and browser versions. It’s been available across browsers since janeiro de 2020. Learn more See full compatibility O método trimStart() remove espaços do começo de uma string. trimLeft() é um apelido para este método. In this article Experimente Sintaxe Descrição Polyfill Exemplos Especificações Compatibilidade com navegadores Veja também Experimente const greeting = " Hello world! "; console.log(greeting); // Expected output: " Hello world! "; console.log(greeting.trimStart()); // Expected output: "Hello world! "; Sintaxe str.trimStart(); str.trimLeft(); Valor retornado Uma nova string representando a string original sem os espaços no começo (fim à esquerda). Descrição Os métodos trimStart() / trimLeft() retornam a string sem os espaços no fim à esquerda. trimLeft() ou trimStart() não altera o valor da string original. Aliasing Para consistência com funções como String.prototype.padStart o nome padrão do método é trimStart. Entretanto, por razões de compatibilidade na web, trimLeft permanece como um apelido para trimStart. Em alguns motores isso significa: js String.prototype.trimLeft.name === "trimStart"; Polyfill js //https://github.com/FabioVergani/js-Polyfill_String-trimStart (function (w) { var String = w.String, Proto = String.prototype; (function (o, p) { if (p in o ? (o[p] ? false : true) : true) { var r = /^\s+/; o[p] = o.trimLeft || function () { return this.replace(r, ""); }; } })(Proto, "trimStart"); })(window); /* ES6: (w=>{ const String=w.String, Proto=String.prototype; ((o,p)=>{ if(p in o?o[p]?false:true:true){ const r=/^\s+/; o[p]=o.trimLeft||function(){ return this.replace(r,'') } } })(Proto,'trimStart'); })(window); */ Exemplos Usando trimStart() O seguinte exemplo mostra uma string em caixa baixa 'foo ': js var str = " foo "; console.log(str.length); // retorna 8 str = str.trimStart(); console.log(str.length); // retorna 5 console.log(str); // retorna 'foo ' Especificações Specification ECMAScript® 2027 Language Specification # sec-string.prototype.trimstart Compatibilidade com navegadores Enable JavaScript to view this browser compatibility table. Veja também String.prototype.trim() String.prototype.trimEnd() Help improve MDN Was this page helpful to you? Yes No Learn how to contribute This page was last modified on 17 de fev. de 2025 by MDN contributors. View this page on GitHub • Report a problem with this content Filter sidebar Clear filter input Objetos Globais String Construtor String() Métodos estáticos String.fromCharCode() String.fromCodePoint() String.raw() Métodos de instância String.prototype.anchor() at() String.prototype.big() String.prototype.blink() String.prototype.bold() String.prototype.charAt() String.prototype.charCodeAt() String.prototype.codePointAt() String.prototype.concat() String.prototype.endsWith() String.prototype.fixed() String.prototype.fontcolor() String.prototype.fontsize() String.prototype.includes() String.prototype.indexOf() isWellFormed() String.prototype.italics() String.prototype.lastIndexOf() String.prototype.link() String.prototype.localeCompare() String.prototype.match() String.prototype.matchAll() String.prototype.normalize() String.prototype.padEnd() String.prototype.padStart() String.prototype.repeat() String.prototype.replace() String.prototype.replaceAll() String.prototype.search() String.prototype.slice() String.prototype.small() String.prototype.split() String.prototype.startsWith() String.prototype.strike() String.prototype.sub() String.prototype.substr() String.prototype.substring() String.prototype.sup() String.prototype.toLocaleLowerCase() String.prototype.toLocaleUpperCase() String.prototype.toLowerCase() String.prototype.toString() String.prototype.toUpperCase() toWellFormed() String.prototype.trim() String.prototype.trimEnd() String.prototype.trimStart() String.prototype.valueOf() String.prototype[@@iterator]() Propriedades de instância String.length Herança Object/Function Métodos estáticos Function.prototype.apply() Function.prototype.bind() Function.prototype.call() Function.prototype.toString() [Symbol.hasInstance]() Propriedades estáticas Function.displayName Function.length Function.name prototype Function.arguments Function.caller Métodos de instância Object.prototype.__defineGetter__() Object.prototype.__defineSetter__() Object.prototype.__lookupGetter__() Object.prototype.__lookupSetter__() Object.prototype.hasOwnProperty() Object.prototype.isPrototypeOf() Object.prototype.propertyIsEnumerable() Object.prototype.toLocaleString() Object.prototype.toString() Object.prototype.valueOf() Propriedades de instância Object.prototype.__proto__ Object.prototype.constructor MDN Your blueprint for a better internet. MDN About Blog Mozilla careers Advertise with us MDN Plus Product help Contribute MDN Community Community resources Writing guidelines MDN Discord MDN on GitHub Developers Web technologies Learn web development Guides Tutorials Glossary Hacks blog Mozilla Website Privacy Notice Telemetry Settings Legal Community Participation Guidelines Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.