배열
const paper = new Array(100)
for(let i=0;i<100;i++){
let arr = new Array(100)
arr.fill(0)
paper[i] = arr
}
const maxValue = Math.max(...arr);
const minValue = Math.min(...arr);
let count = arr.filter(element => 'a' === element).length;
각종 자료형 변환
let n = String(n)
let m = parseInt(m)
let c = parseInt("1000", 2)
let d = num.toString(2)
배열 합 구하기
const arr = [1, 2, 3];
const result = arr.reduce(function add(sum, currValue) {
return sum + currValue;
}, 0);
정렬
const _arr = arr.slice();
_arr.sort(function(a, b) {
return a - b;
});
딕셔너리
const dic = {};
dic["key1"] = "value1";
dic["key2"] = "value2";
dic["key3"] = "value3";
delete dic["key2"]
console.log(dic)
for (let key in dic){
console.log(key, dic[key]);
}
const keys = Object.keys(dic);
console.log(keys);
console.log(keys.length);
console.log("key1" in dic)
console.log("key5" in dic)
set
const arr1 = [1,2,3,4,5,5,5];
const set1 = new Set(arr1);
set1.add(4)
set1.delete(1)
console.log(set1.has(5))
const arr2 = [...set1];
console.log(arr2)
const set2 = new Set([5,6,7,8,8]);
const intersection = new Set([...set1].filter(x => set2.has(x)));
const difference = new Set([...set1].filter(x => !set2.has(x)));
문자열 다루기
const str1 = "Hello World";
const str2 = "asdf!";
const split1 = str1.split(" ");
console.log(split1)
str1.substring(시작인덱스, 종료인덱스);
str1.substr(시작인덱스, 길이);
console.log(str1+str2);
const arr1 = ["Hi", "Bye"];
arr1.join(구분자);
let str3 = "qwe asd zxc";
str3 = str3.replace(" ","");