console.log(typeof "some string"); // "string"

 

===>Built-in Methods : 내장 함수

JavaScript 는 string 을 조작하기 위한 내장 함수(Built-in Methods)들이 존재합니다. 이 메소드들을 사용하면 항상 새로운 string 이 생성됩니다. string 이 immutable object 이기 때문입니다.

console.log("hello".charAt(0)); // "h" : 문자열에서 0번째 문자를 반환합니다.

console.log("hello".toUpperCase()); // "HELLO" : 문자열을 대문자로 바꿉니다.

console.log("Hello".toLowerCase()); // "hello" : 문자열을 소문자로 바꿉니다.

console.log("hello".replace(/e|o/g, "x")); // "hxllx" : 문자열에서 e, o 문자를 x 로 바꿉니다.

console.log("1,2,3".split(",")); // ["1", "2", "3"] : 문자열을 , 로 쪼개서 배열에 담습니다.

 

===>Length Property : 문자열 길이 속성

문자열의 길이 속성입니다. 속성이기 때문에 뒤에 () 를 붙이지 않습니다. 아래 내용을 확인해 보세요.

console.log("Hello".length); // 5 console.log("".length); // 0




출처: https://findfun.tistory.com/62?category=383258 [즐거움을 찾자 Find Fun!!]

Posted by useways
,