Ryu.log

string.localeCompare() 본문

Prev-content

string.localeCompare()

류뚝딱 2018. 11. 12. 16:28

string.localeCompare()

string.localecompare() 메서드는 기준 문자열과 비교했을 때 비교 대상 문자열이 정렬상 전에 오는지, 
후에 오는지 혹은 같은 순서에 배치되는지를 알려주는 숫자를 리턴해준다.
str.localeCompare(비교str)
//stre : 대상 문자
//비교str : 비교할 문자

예제 코드

console.log('a'.localeCompare('b')); // -1
console.log('b'.localeCompare('a')); // 1
console.log('b'.localeCompare('b')); // 0


'Prev-content' 카테고리의 다른 글

Array.prototype.pop()  (0) 2018.11.13
Array.prototype.sort()  (0) 2018.11.12
String.prototype.repeat()  (0) 2018.11.09
Array.from()  (0) 2018.11.05
[ Redux 유용 ] 리액트 App에 손쉽게 store를 연결시켜주는 Provider 컴포넌트  (0) 2018.09.20
Comments