본문 바로가기

JavaScript62

이펙트 용용편 - 서치 육번째 검색 이펙트 이번 이펙트는 정렬하는 기능을 구현했습니다. JS코드 sort를 이용하여 정렬을 구현했습니다. 코드 보기 //반대로 정렬 function sortReverse() { cssProperty.reverse(); updateList(); } // 내림차순 function sortDescending() { cssProperty.sort((a, b) => b.num - a.num); updateList(); } // 오름차순 function sortAscending() { cssProperty.sort((a, b) => a.num - b.num); updateList(); // 알파벳(a-z) 정렬 function sortAlphabet() { cssProperty.sort(function (a, b.. 2022. 10. 21.
배열 메서드 응용2 배열 매서드 응용2 배열 매서드를 응용 해보았습니다. 배열 ["a", "b", "c", "d", "e", "f", "g", "h", "i", "k"] 을 이용하여, b,d,f,h,k 만 출력하게했습니다. 매서드 응용 const num1 = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "k"]; let result1 = num1 .map((e, i) => { if ((i + 1) % 2 == 0) return e; }) .filter((e) => e != null); console.log(result1.join()); 결과 확인하기 const num2 = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "k"]; let result2 .. 2022. 9. 29.
배열 메서드 응용 배열 매서드 응용! 배열 매서드를 응용 해보았습니다. 배열 [100, 200, 300, 400, 500, 600, 700, 800, 900] 을 이용하여, 400,500만 출력되게 해보았습니다. 매서드 응용 const number = [100, 200, 300, 400, 500, 600, 700, 800, 900]; const result1 = number.slice(3, 5).join(","); console.log(result1); 결과 확인하기 const number2 = [100, 200, 300, 400, 500, 600, 700, 800, 900]; const result2 = number2.splice(3, 2).join(","); console.log(result2); 결과 확인하기 con.. 2022. 9. 28.
unshift() / shift() unshift() / shift() unshift() 메서드는 배열 처음 요소에 추가 shift() 메서드는 배열 처음 요소에 삭제 번호 기본값 메서드 리턴값 결과값 // 01 const arrNum = [100, 200, 300, 400, 500]; const arrUnshift = arrNum.unshift(600); // 02 const arrNum2 = [100, 200, 300, 400, 500]; const arrShift = arrNum2.shift(); 2022. 9. 27.
startsWith() / endsWith() startsWith() / endsWith() startsWith() 메서드는 시작하는 문자열에서 문자열을 검색하여 불린으로(true, false) 반환합니다. endsWith() 메서드는 끝나는 문자열에서 문자열을 검색하여 불린(true, false)을 반환합니다. 사용법 "문자열".startsWith(검색 문자열); "문자열".startsWith(검색 문자열, 위치값); "문자열".endsWith(검색 문자열); "문자열".endsWith(검색 문자열, 위치값); 예제 const str1 = "javascript reference" const currentStr1 = str1.startsWith('javascript'); // true const currentStr2 = str1.startsWith(.. 2022. 9. 27.
splice() splice() splice() 메서드는 배열의 기존 요소를 삭제 또는 교체하거나 새 요소를 추가하여 배열의 내용을 변경합니다. 번호 기본값 메서드 리턴값 결과값 //01 const arrNum1 = [100, 200, 300, 400, 500]; const result = arrNum1.splice(2); //02 const arrNum2 = [100, 200, 300, 400, 500]; const result2 = arrNum2.splice(2, 3); //03 const arrNum3 = [100, 200, 300, 400, 500]; const result3 = arrNum3.splice(2, 3, "javascript"); //04 const arrNum4 = [100, 200, 300, 40.. 2022. 9. 27.
728x90
반응형

자바스크립트 사진

JavaScript

자세히보기