{{obsolete_header("37")}}
{{JSRef("Global_Objects", "String")}} {{non-standard_header}}
Summary
The non-standard quote()
method returns a copy of the string, replacing various special characters in the string with their escape sequences and wrapping the result in double-quotes ("
).
Syntax
str.quote()
Examples
In the table below the quote()
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 |
"Hello\n\tworld!" |
Hello |
" \ — ' |
"\" \\ \u2014 '" |
" \ — ' |
Specifications
Not part of any standard. Implemented in JavaScript 1.3.
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
See also
- {{jsxref("JSON.stringify()")}}