JavaScript (63) 썸네일형 리스트형 Attribute 속성 삭제하기 button의 onclick이라는 속성을 삭제해보자. button.removeAttribute("onclick"); class/id값 없는 button : 어떤버튼이 클릭되었는지, 버튼텍스트인식하기 아래와 같은 수정이란 텍스트를 가진 button을 인식해보기로 하자. 수정 document.querySelectorAll("button").forEach(button => { const buttonText = button.innerText.trim(); if (buttonText === '수정') {} }); alert와 confirm의 차이, 예시코드 alert 통보식 안내창 alert("알림창으로 안내드릴게요!"); confirm 허락을 구하는 안내창 if (confirm("정말로 진행하시겠습니까?")) { console.log("진행합니다!"); } else { console.log("취소했습니다."); } hoisting, 사용할 변수를 미리 확인하다 hoisting JavaScript에서 사용할 변수를 미리 확인해 끌어올려지는 작업 sayHello(); // "Hello!" function sayHello() { console.log("Hello!"); } sayHello()함수를 호출하기 전에 함수선언이 있지않아 오류가 나야하지만 호이스팅으로 인해 해당 function 블럭이 최상단으로 끌어올려져 sayHello()가 정상적으로 실행되게된다. *코드의 가독성을 위해 변수와 함수를 사용하기 전에 선언하는 것이 우선권장된다. classList. add/remove/toggle/contains 클래스 목록 관리하기 classList.add(class1, class2, ...) 요소의 클래스 목록에 클래스를 추가, 여러 개의 클래스를 추가할 수 있습니다. classList.remove(class1, class2, ...) 요소의 클래스 목록에서 클래스를 제거, 여러 개의 클래스를 제거할 수 있습니다. classList.toggle(class, force) 요소의 클래스 목록에서 클래스를 추가하거나 제거, 클래스가 이미 존재하면 제거하고, 존재하지 않으면 추가 force 매개 변수를 사용하여 클래스를 강제로 추가 또는 제거할 수 있다. classList.contains(class) 요소의 클래스 목록에 클래스가 존재하는지 확인, true 또는 false를 반환된다. for of 과 for in의 차이 for of은 객체를 반환하고 for in는 index를 반환한다. let array1=[52, 273, 32, 93, 103] for(let element of array1){ document.write(element+" "); } document.write(" "); for(let i in array1){ document.write(array1[i]+" "); } Math.min/max 최소값, 최대값 구하기 최소값, 최대값 구하기 Math.min.apply Math.max.apply let array2 = [273, 52, 103, 57, 271]; let min=Number.MIN_VALUE; let max=Number.MAX_VALUE; min= Math.min.apply(null, array2); max= Math.max.apply(null, array2); document.write(`가장 작은 수${min}`+" "); document.write(`가장 큰 수${max}`); sort(fnc(a, b{}return a-b)) + reverse() 내림차순 sort(fnc(a, b{}return a-b)) + reverse() 내림차순 let array = [52, 71, 32, 103, 273, 93] array.sort(function (a, b) {return a - b}) document.write(array.reverse()); //273,103,93,71,52,32 https://standout.tistory.com/611 sort(fnc(a, b{}return a-b)) 오름차순 sort(fnc(a, b{}return a-b)) 오름차순 let array = [52, 71, 32, 103, 273, 93] array.sort(function (a, b) {return a - b}) document.write(array); //32,52,71,9.. 이전 1 2 3 4 5 6 7 8 다음