Trim is a useful function available in languages like Java & PHP which removes the leading and traling whitespace(s) from a String.トリムは、便利な機能がご利用の言語でのJava & PHPのような大手とtraling空白文字を削除する(秒)より、文字列です。 Unfortunately Javascript doesn’t natively provide trim functionality to the String object.残念ながらJavaScriptをネイティブではありませんトリムの機能を提供する文字列オブジェクトを作成します。 Fortunately there is a simple solution.幸いには、シンプルなソリューションです。 Place the following code near the top of your Javascript file (or inline script) to add trim() functionality to all String objects.場所は、次のコードの上部にしてJavaScriptファイル(またはインラインスクリプト)を追加するトリム( )の機能をすべての文字列オブジェクトです。

 String prototype.trim = function() {     a = this.replace(/^\s+/, '');     return a.replace(/\s+$/, ''); }; 文字列prototype.trim =関数( ) (する= this.replace ( / ^ \秒+ / 、 '' ) ;戻りa.replace ( / \秒+ $ / 、 '' ) ; ) ; 

This underlines one of the beauty (or beast depending on who you ask) of Javascript - the ability to add functionality to an existing class, even native classes like String, by accessing its prototype.この下線の1つの美しさ(またはwhoことを聞くのに応じてビースト)のJavaScriptを-する能力を既存のクラスに機能を追加するも、ネイティブクラスのような文字列を、そのプロトタイプにアクセスします。

Now you can use trim() on any String in your code.今すぐ使用することができますトリム( )を任意の文字列のコードです。