| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/split | [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.
split() String .
const str = "The quick brown fox jumps over the lazy dog.";
const words = str.split(" ");
console.log(words[3]);
// Expected output: "fox"
const chars = str.split("");
console.log(chars[8]);
// Expected output: "k"
const strCopy = str.split();
console.log(strCopy);
// Expected output: Array ["The quick brown fox jumps over the lazy dog."]
split();
split(separator);
split(separator, limit);
:
: ("") , (grapheme cluster) () , UTF-16 . How do you get a string to a character array in JavaScript? .
separator Optionallimit Optional . split() separator limit . limit . .
separator Array.
separator . separator . separator , str . separator . separator .
separator , separator ( ) .
Note:
separator.
split() :
split() . separator .
const myString = "";
const splits = myString.split();
console.log(splits);
// [""]
. ( ) , .
function splitString(stringToSplit, separator) {
var arrayOfStrings = stringToSplit.split(separator);
console.log('The original string is: "' + stringToSplit + '"');
console.log('The separator is: "' + separator + '"');
console.log(
"The array has " +
arrayOfStrings.length +
" elements: " +
arrayOfStrings.join(" / "),
);
}
var tempestString = "Oh brave new world that has such people in it.";
var monthString = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
var space = " ";
var comma = ",";
splitString(tempestString, space);
splitString(tempestString);
splitString(monthString, comma);
.
The original string is: "Oh brave new world that has such people in it."
The separator is: " "
The array has 10 elements: Oh / brave / new / world / that / has / such / people / in / it.
The original string is: "Oh brave new world that has such people in it."
The separator is: "undefined"
The array has 1 elements: Oh brave new world that has such people in it.
The original string is: "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
The separator is: ","
The array has 12 elements: Jan / Feb / Mar / Apr / May / Jun / Jul / Aug / Sep / Oct / Nov / Dec
split() 0 , . split() nameList .
var names = "Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ";
console.log(names);
var re = /\s*(?:;|$)\s*/;
var nameList = names.split(re);
console.log(nameList);
.
Harry Trump ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand
[ "Harry Trump", "Fred Barney", "Helen Rigby", "Bill Abel", "Chris Hand", "" ]
split() 3 .
var myString = "Hello World. How are you doing?";
var splits = myString.split(" ", 3);
console.log(splits);
.
["Hello", "World.", "How"]
RegExp separator () , .
var myString = "Hello 1 word. Sentence number 2.";
var splits = myString.split(/(\d)/);
console.log(splits);
.
[ "Hello ", "1", " word. Sentence number ", "2", "." ]
var myString = "this|is|a|Test";
var splits = myString.split(["|"]);
console.log(splits); //["this", "is", "a", "Test"]
var myString = "ca,bc,a,bca,bca,bc";
var splits = myString.split(["a", "b"]);
// myString.split(['a','b']) myString.split(String(['a','b']))
console.log(splits); //["c", "c,", "c", "c", "c"]
split() : .
var str = "asdfghjkl";
var strReverse = str.split("").reverse().join("");
// 'lkjhgfdsa'
// split() reverse() join() grapheme clusters , ([esrever](https://github.com/mathiasbynens/esrever) ).
var str = "resume";
var strReverse = str.split(/(?:)/u).reverse().join("");
// => "emuser"
: === .
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.split |
String.prototype.charAt()String.prototype.indexOf()String.prototype.lastIndexOf()Array.prototype.join()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 |