표준 내장 객체 내용은 다 외울건 아니고 그냥 이런게 있구나... 나중에 쓸 일 있으면 참고하려고 작성합니다.
주어진 문자열의 길이를 반환
Hello != hello
-1
반환const str = '1234567' //str.length = 7
console.log(str.padEnd(10,"0")) // 1234567000
const str2 = '1234567890123'
console.log(str2.padEnd(10,"0")) // 1234567890123
1234567000
이라는 새로운 문자를 반환했다..padEnd()
와 반대라고 생각하면 됨).padStart()
역시 대상 문자의 길이가 지정된 길이보다 크면 아무런 변화없이 그대로 출력된다. (원형을 변형시키지 않음)const str = '1234567' //str.length = 7
console.log(str.padEnd(10,"0")) // 0001234567
const str = 'Hello, Hello!?'
console.log(str.replace('Hello', 'Hi')) // Hi, Hello!?
console.log(str.replace(/Hello/g, 'Hi')) // Hi, Hi!?
/Hello/g
의 의미는 대상 문자열에서 Hello 라는 문자와 매칭되는 것을 모두 검색한다는 의미const str = 'Hello World!'
console.log(str.slice(0,5)) // 0번째~4번째 "Hello"
console.log(str.slice(6,-1)) // "World"
console.log(str.slice(6)) // "World!"
..., -3, -2, -1
인덱싱 값을 갖게 됨.str
에서 str[-1] = !
, str[-2] = d
, str[-3] = l
...const str = 'Apple, Banana, Cherry'
console.log(str.split(', ')) //['Apple', 'Banana', 'Cherry']
const hello = "Hi guys. Nice to meet you."
console.log(hello.toUpperCase()) //"HI GUYS. NICE TO MEET YOU."
console.log(hello.toLowerCase()) //"hi guys. nice to meet you."
trim()
을 사용할 수 있다.const str = " Hello guys! "
console.log(hello.trim()) // "Hello guys!"
console.log(hello) // " Hello guys! " 원본은 바뀌지 않음. 공백이 그대로 출력됨