본문 바로가기
반응형

전체 글483

[JS] slice & splic Array.prototype.slice() slice() 메소드는 begin부터 end 전까지의 복사본을 새로운 배열 객체로 반환한다. 원본 배열은 수정되지 않는다. slice(start, end) start : 추출 시작점 인덱스 undefined인 경우: 0부터 slice 음수를 지정한 경우: 배열의 끝에서부터의 길이를 나타낸다. slice(-2)를 하면 배열의 마지막 2개의 요소를 추출 배열의 길이와 같거나 큰 수를 지정한 경우: 빈 배열을 반환 end : 추출 종료 기준 인덱스 (end는 제외) 지정하지 않을 경우: 배열의 끝까지 slice 음수를 지정한 경우: 배열의 끝에서부터의 길이를 나타낸다. slice(2, -1)를 하면 세번째부터 끝에서 두번째 요소까지 추출 배열의 길이와 같거나 큰 수를.. 2021. 6. 25.
[JS] 2차열 배열 2차원 배열이란? 배열 안에 또 다른 배열이 존재하는 것. JS는 모든 것이 객체이기 때문에 배열의 각 요소를 다시 배열로 정의해 중첩하는 식으로 배열을 구현한다. Example let test = [['apple', 2], ['banana', 5], ['mango', 3], ['mandarine', 1]]; console.log(test[0][0]); // apple test[0] = ['apple', 2] -> ['apple', 2][0] = 'apple' test.push(['grape', 7]); console.table(test); // test = [['apple', 2], ['banana', 5], ['mango', 3], ['mandarine', 1], ['grape', 7]]; test... 2021. 6. 24.
[JS] D-day 만들기 D-day 만들기 function inIt() { const nowDate = new Date(); const dDay = new Date('2021-09-30 18:00'); const countDown = dDay - nowDate ; // 1000ms(1초) * 60(1분) * 60(1시간) * 24(1일) * 365(1년) const countDownday = Math.floor(countDown/(1000*60*60*24)); const countDownhour = Math.floor((countDown%(1000*60*60*24))/(1000*60*60)); const countDownMins = Math.floor((countDown%(1000*60*60))/(1000*60)); const .. 2021. 6. 9.
반응형