Skip to content

ProtoString protoTrim() Method

Seth Clydesdale edited this page Jun 2, 2015 · 6 revisions

<< Back to Polyfill Methods

Examples

Trimming a string of whitespace on both sides.

'    Hello world !    '.protoTrim(); // returns 'Hello world !'

Passing left as the parameter will trim the left side of whitespace.

'    Hello world !    '.protoTrim('left'); // returns 'Hello world !    '

Passing right as the parameter will trim the right side of whitespace.

'    Hello world !    '.protoTrim('right'); // returns '    Hello world !'

Description

The protoTrim method can be used as a polyfiller for the native trim(), trimLeft(), and trimRight() methods. It's used to trim whitespace on a specific side, or both sides of a string.

Syntax

String.protoTrim(type);

Parameters

Parameter Description
type A string which determines the side of the string to be trimmed. Possible values are left, right, and both. Defaults to both if left undefined.
Clone this wiki locally