스프레드연산자 (...) spread 연산
하나로 뭉쳐 있는 여러 데이터들의 집합을 개별적인 값으로 분류 Iterable객체에 적용할 수 있다(Array, String, Map, Set, DOM nodelist, arguments) 예제) let arr = [1, 2, 3, 4]; let a = { ...arr }; let b = [...arr]; let arrObject = { '0': 1, '1': 2, '2': 3, '3': 4 } console.log(...arr); //1 2 3 4 console.log(a); // { '0': 1, '1': 2, '2': 3, '3': 4 } console.log(b); // [ 1, 2, 3, 4 ] 함수의 인자값으로 넣는 예 function sum(a, b, c) { return a + b + c;..
2022. 7. 21.
자바스크립트_배열
1. length 길이를 반환한다. const numbers = [1,2,3,4] const fruits= ['Apple','Banana','Cherry'] console.log(numbers.length) 4 나옴. 2. concat 배열을 이어준다. const numbers = [1,2,3,4] const fruits= ['Apple','Banana','Cherry'] console.log(numbers.concat(fruits)) 3. forEach 배열데이터의 개수만큼 콜백이 실행된다. 콜백함수의 매개변수에 들어가는 것은 첫번째는 반복되는 각각의 아이템, 두번째는 횟수이다. const fruits= ['Apple','Banana','Cherry'] fruits.forEach(function(ele..
2022. 7. 21.
비구조화할당
비구조화할당= 배열이나 객체의 속성을 해체하여 그 값을 개별 변수에 담을 수 있게 하는 JavaScript 표현식 ex1) test.js const studnt = { apple="사과", banana="반하나", kiwi="키위"} const{apple,banana,kiwi} = student console.log(apple) ==> 이거 하면 사과 나온다! 어떻게 이해해야 하냐면 const{apple,banana,kiwi} = student 에서 apple, banana, kiwi값 student에서 뽑아와~ 라는 의미임. ex2) 다음은 배열이다. 배열은 index값이 자동으로 주어지므로 차례대로 할당된다. const user = ["김사과","반한","다람쥐"] const [kim,ban,oh] ..
2022. 6. 28.