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."]
Ref. https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/split
String.prototype.split() - JavaScript | MDN
split() 메서드는 String 객체를 지정한 구분자를 이용하여 여러 개의 문자열로 나눕니다.
developer.mozilla.org
'Develop > JavaScript' 카테고리의 다른 글
Uncaught TypeError: Cannot read property 'split' of undefined (0) | 2022.05.24 |
---|---|
Casting between Numbers and String in JavaScript (0) | 2022.05.23 |
Slicing string in JavaScript (0) | 2022.05.20 |
댓글