티스토리 뷰

문자열을 자르기 위해 split 함수를 사용하여 다음과 같은 코드를 작성하였을 때, jumps는 어떻게 될까?

const str = 'The quick brown fox jumps over the lazy dog.';

const strCopy = str.split('jumps');
console.log(strCopy);

순간적으로 나는 다음과 같이 기대하였으나

Array ["The quick brown fox ", "jumps", " over the lazy dog."]

결론은 다음과 같다. (기본적인 함수가 헷갈릴 때가 더러있다...ㅠ)

Array ["The quick brown fox ", " over the lazy dog."]

 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

 

String.prototype.split() - JavaScript | MDN

The split() method takes a pattern and divides a String into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

developer.mozilla.org

 

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함