REFACTOR

본 글은 HTML5, CSS 학습한 상태에서 작성한 글입니다.


















문자열 함수




charAt(인자) :


지정한 인덱스의 문자값을 반환


"hello".charAt(str.length###1) 


-> 


"0"



------------------------------------------------------------------



indexOf(인자) , lastIndexOf(인자):


indexOf : 인자의 내용을 탐색해 index 반환


lastIndexOf : indexOf와 동일하나 문자열 앞이 아닌 뒤에서부터 시작



"hello".indexOf("h") 


->


1



"hello".lastindexOf("h")


->


5



------------------------------------------------------------------


startsWith(검색문자,찾기시작할문자열 위치(기본값 0 ) :

어떤 문자열이 특정 문자로 시작하는지 확인 할 수 있으며, 
그 결과는 ture or false로 반환된다.


var str = 'To be, or not to be, that is the question. ';


str.startsWith('To be'); 

->

true


str.startsWith('not to be'); 

->

flase


str.startsWith('not to be',10); 

->

true




------------------------------------------------------------------


endsWith(문자열,옵션) :


어떤 문자열에서 특정 문자열로 끝나는지를 확인할 수 있다.





var str = 'To be, or not to be, that is the question. ';




str.endsWith('question.'); 

->

true


str.endsWith('to be'); 

->

flase


str.endsWith('to be',19); 

->

true



------------------------------------------------------------------




match(인자) :


인자의 내용을 탐색해 반환, 여러개 있으면 배열로 반환


보통 인자는 정규식으로 작성 


"hello".match(/l/g) 


->


["l","l"]




------------------------------------------------------------------




replace(인자,인자) :


앞의 인자에 문자열에서 찾을 내용을 적고, 뒤에 인자에 변경할 내용을 적는다



"hello".replace("ello","i")


->


"hi"



------------------------------------------------------------------



split(인자) , join(인자) :


split : 인자의 내용을 기준으로 문자열을 잘라 배열로 반환


join : 인자의 내용을 기준으로 배열을 문자열로 합침(미입력시 ,로 연결)



"hello world".splic("") 


->


["hello","world"]





["hello","world"].join("")



->


"hello world"



------------------------------------------------------------------




substring(시작,끝) :


문자열에서 시작과 끝 인덱스로 문자열 반환



"hello".substring(1,2) 


->


"e"




------------------------------------------------------------------



substr(시작,길이) :


문자열에서 시작 인덱스와 길이로 문자열 반환


"hello".substr(1,2)



->


"el"













출처: http://takeuu.tistory.com/102  [워너비스페셜]

http://kssong.tistory.com/26






profile

REFACTOR

@usnooy_

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!

검색 태그