| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
* Some parts of this feature may have varying levels of support.
String ( ) .
.
'string text' "string text" " espaol Deutsch English portugus norsk bokml "
String .
String(thing);
thing`hello world` `hello! world!` `hello ${who}` tag `<a>${who}</a>`
.
\XXX |
8 Latin-1 |
\' |
|
\" |
|
\\ |
|
\n |
|
\r |
|
\v |
|
\t |
|
\b |
|
\f |
|
\uXXXX |
|
\u{X} ... \u{XXXXXX} |
|
\xXX |
Latin-1 |
: , JavaScript . .
, . .
+ .
let longString =
" " +
" " +
" .";
("\") . .
let longString =
" \
\
.";
.
. (length), + += , (substring) , indexOf() , (substring) substring() .
. charAt() :
return "cat".charAt(1); // returns "a"
(ECMAScript 5 ) , :
return "cat"[1]; // returns "a"
([ ]) , . , . ( Object.defineProperty() .)
C strcmp() . JavaScript less-than greater-than :
var a = "a";
var b = "b";
if (a < b) {
// true
console.log(a + " is less than " + b);
} else if (a > b) {
console.log(a + " is greater than " + b);
} else {
console.log(a + " and " + b + " are equal.");
}
String localeCompare() .
String JavaScript String . (Boolean true .)
( ) (. new ) String (primitive strings). JavaScript String , String . , JavaScript .
var s_prim = "foo";
var s_obj = new String(s_prim);
console.log(typeof s_prim); // Logs "string"
console.log(typeof s_obj); // Logs "object"
String eval() . eval ; String , . :
var s1 = "2 + 2"; // creates a string primitive
var s2 = new String("2 + 2"); // creates a String object
console.log(eval(s1)); // returns the number 4
console.log(eval(s2)); // returns the string "2 + 2"
, String , .
String valueOf() .
console.log(eval(s2.valueOf())); // returns the number 4
String()Creates a new String object. It performs type conversion when called as
a function, rather than as a constructor, which is usually more useful.
String.fromCharCode(num1 [, ...[, numN]]).
String.fromCodePoint(num1 [, ...[, numN).
String.raw()(raw template string) .
String.prototype.lengthReflects the length of the string. Read-only.
String.prototype.at(index)Returns the character (exactly one UTF-16 code unit) at the specified index. Accepts negative integers, which count back from the last string character.
String.prototype.charAt(index)Returns the character (exactly one UTF-16 code unit) at the specified
index.
String.prototype.charCodeAt(index)Returns a number that is the UTF-16 code unit value at the given
index.
String.prototype.codePointAt(pos)Returns a nonnegative integer Number that is the code point value of the UTF-16
encoded code point starting at the specified pos.
String.prototype.concat(str [, ...strN ])Combines the text of two (or more) strings and returns a new string.
String.prototype.includes(searchString [, position])Determines whether the calling string contains searchString.
String.prototype.endsWith(searchString [, length])Determines whether a string ends with the characters of the string
searchString.
String.prototype.indexOf(searchValue [, fromIndex])Returns the index within the calling String object of the first
occurrence of searchValue, or -1 if not found.
String.prototype.lastIndexOf(searchValue [, fromIndex])Returns the index within the calling String object of the last
occurrence of searchValue, or -1 if not found.
String.prototype.localeCompare(compareString [, locales [, options]])Returns a number indicating whether the reference string
compareString comes before, after, or is equivalent to the
given string in sort order.
String.prototype.match(regexp)Used to match regular expression regexp against a string.
String.prototype.matchAll(regexp)Returns an iterator of all regexp's matches.
String.prototype.normalize([form])Returns the Unicode Normalization Form of the calling string value.
String.prototype.padEnd(targetLength [, padString])Pads the current string from the end with a given string and returns a new string of
the length targetLength.
String.prototype.padStart(targetLength [, padString])Pads the current string from the start with a given string and returns a new string
of the length targetLength.
String.prototype.repeat(count)Returns a string consisting of the elements of the object repeated
count times.
String.prototype.replace(searchFor, replaceWith)Used to replace occurrences of searchFor using
replaceWith. searchFor may be a string
or Regular Expression, and replaceWith may be a string or
function.
String.prototype.replaceAll(searchFor, replaceWith)Used to replace all occurrences of searchFor using
replaceWith. searchFor may be a string
or Regular Expression, and replaceWith may be a string or
function.
String.prototype.search(regexp)Search for a match between a regular expression regexp and
the calling string.
String.prototype.slice(beginIndex[, endIndex])Extracts a section of a string and returns a new string.
String.prototype.split([sep [, limit] ])Returns an array of strings populated by splitting the calling string at occurrences
of the substring sep.
String.prototype.startsWith(searchString [, length])Determines whether the calling string begins with the characters of string
searchString.
String.prototype.substring(indexStart [, indexEnd])Returns a new string containing characters of the calling string from (or between) the specified index (or indices).
String.prototype.toLocaleLowerCase( [locale, ...locales])The characters within a string are converted to lowercase while respecting the
current locale.For most languages, this will return the same as
toLowerCase().
String.prototype.toLocaleUpperCase( [locale, ...locales])The characters within a string are converted to uppercase while respecting the
current locale.For most languages, this will return the same as
toUpperCase().
String.prototype.toLowerCase()Returns the calling string value converted to lowercase.
String.prototype.toString()Returns a string representing the specified object. Overrides the
Object.prototype.toString() method.
String.prototype.toUpperCase()Returns the calling string value converted to uppercase.
String.prototype.trim()Trims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.
String.prototype.trimStart()Trims whitespace from the beginning of the string.
String.prototype.trimEnd()Trims whitespace from the end of the string.
String.prototype.valueOf()Returns the primitive value of the specified object. Overrides the
Object.prototype.valueOf() method.
String/Symbol.iteratorReturns a new iterator object that iterates over the code points of a String value, returning each code point as a String value.
toString() , toString() "" String . String null undefined . :
var outputStrings = [];
for (var i = 0, n = inputValues.length; i < n; ++i) {
outputStrings.push(String(inputValues[i]));
}
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string-objects |
This page was last modified on 2026 7 15 by MDN contributors.
StringString.prototype.anchor()String.prototype.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()String.prototype.isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()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()String.prototype.toWellFormed()String.prototype.trim()String.prototype.trimEnd()String.prototype.trimStart()String.prototype.valueOf()String.prototype[@@iterator]()Object/FunctionObject.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()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |