210813 오늘은 js 배열과 함수 기초에 대해서 학습했다.
// 배열을 변수에 저장하는 3가지 방법
let 변수(인스턴스 네임) = new Array();
//변수[0] = "값1"
//변수[1] = "값2"
//변수[2] = "값3"
let 변수 = new Array(3);
let 변수 = [값1, 값2, 값3]; // 기본적으로 가장 많이 사용
/*
method
reverse() 역순 반환
slice(1, 2) index 1~2직전까지 반환
sort() 오름차순으로 정렬
join('구분자') 구분자로 데이터 연결
concat() 하나로 결합
shift() 첫 index[0] 데이터 삭제
pop() 마지막 index 데이터 삭제
unshift(값) 첫 index[0] 새 데이터 중첩하여 추가
push(값) 마지막 index에 새 데이터 중첩하여 추가
*/
let today = new Date();
let days = ['일', '월', '화', '수', '목', '금', '토']
let nowDay = days[today.getDay()]; // getDay()는 0~6까지 요일을 숫자로 구하는 메서드
document.write(nowDay + '<br />');
let myLotto = []; // 6자리 index 5
let arrLotto = [];
let idx = 0;
for (let i = 1; i < 46; i++) {
arrLotto.push(i);
}
while (myLotto.length < 6) {
idx = Math.floor(Math.random() * arrLotto.length + 0);
myLotto.push(arrLotto[idx]);
arrLotto.splice(idx, 1); // idx부터 1개 삭제(idx에 해당하는 번호 삭제)
}