String.prototype.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."]

'언어 정리 > JavaScript' 카테고리의 다른 글

String.prototype.repeat()  (0) 2022.11.12
Array.prototype.sort()  (0) 2022.11.12
Array.prototype.reverse()  (0) 2022.11.09
Array.prototype.join()  (0) 2022.11.09
Array.proptotype.filter()  (0) 2022.11.06