[JavaScript] 문자열 대소문자 변환
.toUpperCase() : 문자열 대문자로 변환 .toLowerCase() : 문자열 소문자로 변환
- SW공부/JavaScript
- · 2023. 2. 18.
[JQuery] 값을 실시간으로 가져오는 함수
$("#id").on("propertychange change keyup paste input", function() {}
- SW공부/JavaScript
- · 2023. 2. 12.
1. Function.prototype.apply(this객체, 함수에 전달할 배열) 문자열에서 최대값, 최소값을 구할 때는 Math.max(), Math.min()을 사용했다. 배열에서 가장 큰 수를 구할 때는 Function.prototype.apply() 의 형태를 이용해서 Math.max.apply() 로 최대값을 구할 수 있다. 첫 번째 파라미터에는 this객체, 두 번째 파라미터에는 함수에 전달할 배열 사용. this를 지정하지 않으려면 null을 쓰고, 이는 window를 가리키게 된다. let array = [2, 6, 9, 3, 4]; let num = Math.max.apply(null, array); console.log(num); //9 2. 스프레드 연산자(...) 사용 스프레드 ..
arr.join([separator]) separator 안에는 합쳐진 배열의 요소를 구분할 수 있는 기호가 들어감 () -> 쉼표로 구분, ("") -> 공백없이 구분 에 주의! var arrChar = ['hello', 'world', '!']; var ex1 = arrChar.join(); var ex2 = arrChar.join(", "); var ex3 = arrChar.join(""); var ex4 = arrChar.join("-"); console.log(ex1); //hello,world,! console.log(ex2); //hello, world, ! console.log(ex3); //helloworld! console.log(ex4); //hello-world-! 참고자료: htt..
arr.sort([compareFunction]) compareFunction : 두 개의 파라미터를 비교하는 compare 함수의 반환값에 따라 정렬 순서(오름차순, 내림차순 등)를 정의. compareFunction에 아무것도 넣지 않으면 유니코드 순서로 정렬됨. //ex1 var arrNums = [4, 2, 7, 1]; arrNums.sort(); console.log(arrNums); //[1, 2, 4, 7] //ex2 //숫자는 문자열로 변환되어 유니코드순으로 2, 20, 5 의 순서가 됨. var arrNums2 = [2, 5, 20]; arrNums2.sort(); console.log(arrNums2); //[2, 20, 5] //ex3 //대문자가 소문자보다 먼저 옴. var arrC..
.split() 메서드 string.split(separator, limit) separator : 문자를 분할하는 기준 limit : 배열 요소의 최대 개수 (지정 개수 이후의 문자는 담지 않음) 매개변수 separator 에 빈 문자열("")을 지정하면 모든 문자를 따로 배열에 담을 수 있음 var strValue = "hello" strValue = strValue.split(""); console.log(strValue); //['h', 'e', 'l', 'l', 'o'] 매개변수 separator 에 쉼표, 하이픈 등을 넣을 수 있음 var strValue = "hello, world" strValue = strValue.split(','); console.log(strValue); //['he..
.toUpperCase() : 문자열 대문자로 변환 .toLowerCase() : 문자열 소문자로 변환
$("#id").on("propertychange change keyup paste input", function() {}