js : https://www.youtube.com/playlist?list=PLEOnZ6GeucBW11uFNvzxToKym9Zv74hxh
https://developer.mozilla.org/ko/docs/Web/JavaScript/Data_structures
Boolean
Null
Undefined
Number
String
Symbol
Object
-https://developer.mozilla.org/ko/ 참고
window.open() : 새로운 창 생성 (Chrome)
parseInt()
String(num) : 숫자 or 숫자값을 문자열로 변환
prompt : alert 입력창 (style 적용 불가)
const name = prompt("이름 입력.");
// name = 입력한 값 할당
// 미 입력시 name = null
const check = confirm("20세 이상입니까?")
// 확인 버튼 >> check = true
// 취소 버튼 >> check = false
let a = 1;
console.log(a + a);
->2
console.log(String(a) + String(a))
->11
let a = 3;
typeof a;
console.log(typeof a);
-> "number"
-> number
let array = [1, 2, 3, 4]
array.every(function (item) {
return item < 6
});
->true
array.every(function (item) {
return item < 4
});
->false
var arr1 = [1, 2, 1, 3, 1];
arr1.**indexOf**(1);
-> 0
arr1.**indexOf**(1,1);
-> 2
arr1.**indexOf**(1,4);
-> 4
const str = "one, two";
const str1 = str.split(",");
const str2 = str.split(" ");
const str3 = str.split("");
console.log(str1); -> ["one", " two"]
console.log(str2); -> ["one,", "two"]
console.log(str3); -> ["o", "n", "e", "," " ", "t", "w", "o"]
const array = ['A', 'B', 1];
console.log(array.join());
-> "A,B,1"
console.log(array.join(""));
-> "AB1"
console.log(array.join("-"));
-> "A-B-1"
let array = [1, 'a'];
console.log(array.push('b', 2));
-> 4
console.log(array);
-> [1, 'a', 'b', 2]
let array = ['a', 'b', 1];
console.log(array.pop());
-> 1
console.log(array);
-> ['a', 'b']
let array = [1, 'a'];
console.log(array.unshift('b', 0));
-> 4
array
-> ["b", 0, 1, "a"]
let array = ['a', 1, 2];
console.log(array.shift());
-> "a"
console.log(array);
-> [1, 2]
let array = ['a', 'b', 1, 2];
array.reverse();
-> [2, 1, 'b', 'a']
(a-b === 0 || a-b === -1 || a-b === 3)
-> [-1, 0, 3].includes(a-b)
var array = [5,12,8,130,44]
array.find(a => a > 10)
-> 12
(10보다 큰 수를 가장 먼저 만족시키는 값은 12)
Array(num) : num개의 빈 공간 생성, undefined도 없는 empty로 생성됨
Array.from(array) : array배열 복사 깊은복사
const arr = [1,2,3];
const arr1 = Array.from(arr);
const arr2 = Array.from(arr, x => x + x);
arr === [1,2,3]
arr1 === [1,2,3]
arr2 === [2, 4, 6]
const array = [1, 2, 3, 4];
array1.filter(function (each, index, originArray) {
return index < 2;
});
-> [1, 2]
const array1 = [1, 2, 3, 4, 5];
array1.fill(0, 2, 4);
-> array === [1, 2, 0, 0, 5]
array1.fill(5, 2);array1[2]부터 5로 채움
-> array === [1, 2, 5, 5, 5]
array1.fill(6);6으로 다 채움
-> array === [6, 6, 6, 6, 6]
const array1 = [-2, -1, 0, 1, 2]
array.map(function(each, index) {
return each * index;
})
-> [-0, -1, 0, 3, 8]
const array = [0, 1, 2];
array.forEach(function (each1, each2, originArray) {
console.log(each1, each2 + 2, originArray)
});
-> 0 2 [0, 1, 2]
1 3 [0, 1, 2]
2 4 [0, 1, 2]
const array = ['a', 1];
array.concat('c', 3);
-> ["a", 1, "c", 3]
const array = ['a', 'b', 3, 4];
const array1 = array.splice(1, 2);console.log(array);
-> ["b", 3]
console.log(array1);
-> ["a", 4]
const array = ['a', 'b', 3, 4];
const array1 = array.splice(1, 3);console.log(array);
-> ["a", "b", 3, 4]
console.log(array1);
-> ["b", 3]
let a = 1.2;
Math.ceil(a);
-> 2
Math.random() : 1미만의 랜덤의 숫자
Math.abs(a) : 숫자a의 절댓값 반환
var obj = {
a: 1,
b: [2, 3],
5: { h: 10 }
}
Object.keys(obj);
-> ["5", "a", "b"];
var obj = {
a: 1,
b: [2, 3],
5: { h: 10 }
}
Object.values(obj);
-> [{ h: 10 }, 1, [2, 3]]
var obj = {
a: 1,
b: [2, 3],
5: { h: 10 }
}
Object.entries(obj)
->[["5", { h: 10 }], ["a", 1], ["b", [2, 3]]]
0: ["5", { h: 10 }]
1: ["a", 1]
2: ["b", [2, 3]]
(function() {
return console.log(1);
})
같은의미
( () => {
console.log(1)
});
element.addEventListener('click', function () {
alert('누름!');
});
-> element를 클릭할 때마다 '누름!'창 표시
'click' -> 좌클릭
'contextmenu' -> 우클릭
**target.appendChild(a) : target요소 안쪽, 가장 뒤에 자식 요소 a 생성
**target.prepend(a) : target요소 안쪽, 가장 앞에 자식 요소 a 생성
setTimeout(()=>{}a) : 설정된 시간(a) 후 코드 실행 후 종료, a=millisecond
setTimeout(() => {
console.log(1)
}, 3000)
console.log(2)
-> 2
(3초 후)-> 1
var a = 0;
setInterval(function() {
console.log(a);
return a++;
}, 1000);
(1초 후) -> 1
(2초 후) -> 2
(3초 후) -> 3
---(반복)---
var num = 0;
var abc;
function name() {
abc = setInterval(function() {
console.log(num);
}, 1000)}
-> 0
-> 0
--(반복)--clearInterval(abc);
--(setInterval 정지)--
--> css의 'classname' class를 element에 추가
--> css의 'classname' class를 element에서 제거
--> css의 'classname' class가 element에 있는지 확인
(있으면 true, 없으면 false값 반환)
document.getElementById('Idname') : Idname과 일치하는 id를 가진 요소를 객체로 반환
document.querySelector()
document.querySelectorAll()
document.createElement('name')
document.title
Element.innerHTML
ex)
border-radius : 20%;
--> element.style.borderRadius = '20%';