--- title: String.prototype.quote() slug: Web/JavaScript/Reference/Global_Objects/String/quote tags: - String - String Methods translation_of: Archive/Web/JavaScript/String.quote ---
{{JSRef}} {{obsolete_header("37")}} {{non-standard_header}}

特殊文字をエスケープシーケンスで置換しダブル・クォーテーション(")でラップした文字列のコピーを返します。

構文

str.quote()

Return value

A new string representing the original string wrapped in double-quotes, with any special characters escaped.

In the table below thequote()method replaces any special characters and wraps the strings in double-quotes. Also note the third column where a wrapped {{jsxref("Global_Objects/eval", "eval()")}} evaluates the escape sequences again.

str str.quote() eval( str.quote() )
Hello world! "Hello world!" Hello world!
Hello
        world!
"Hello\n\tworld!" Hello
        world!
" \ — ' "\" \\ \u2014 '" " \ — '

仕様

Not part of any standard. Implemented in JavaScript 1.3.

ポリフィル

if (!String.prototype.quote)
    String.prototype.quote = function(){
        return JSON.stringify( this ); // since IE8
    }

ブラウザ互換性情報

{{Compat("javascript.builtins.String.quote")}}

関連情報