본문 바로가기

javascript28

for Each for Each [immutable] - 불변 arr.forEach(callback(currentvalue[, index[, array]])[, thisArg]) 배열의 길이만큼 반복 실행 인자로 전달되며, 실행 여부를 해당 함수가 결정하는 형태의 함수를 callback for Each 매개변수 callback 각 요소에 대해 실행할 함수 currentValue 처리할 현재 요소 index 처리할 현재 요소의 인덱스 array forEach()를 호출한 배열 thisArg callback을 실행할 때 this로 사용할 값 리턴 값 undefined for Each 실행 let arr = ['Security', 'Info', 'World']; arr.forEach(function(curr, index, a.. 2020. 6. 20.
객체 객체 (Object) 주소록에 주로 사용 let user = { firstName : 'Lee', lastName : 'Sangho', email : 'jesussangho@gmail.com', city : 'Seoul', phone : '010-0000-0000' }; firstName : 키(key) 'Lee' : 값(value) 객체는 키와 값 쌍(key-value pair)으로 이루어져 있음 Dot notaion (object.key) let user = { firstName : 'Lee', lastName : 'Sangho', email : 'jesussangho@gmail.com', city : 'Seoul', phone : '010-0000-0000' }; /*=================.. 2020. 6. 18.
push, pop, shift, unshift, slice arr.push() - element 추가 (맨 끝 value) arr.pop() - element 삭제 (맨 끝 value) arr.unshift() - element 추가 (맨 앞 value) arr.shift() - element 삭제 (맨 앞 value) slice - 배열을 반환 2020. 6. 18.
타입 구분 /* ======================*/ // 타입 구분 typeof '문자열' "string" typeof 123 "number" typeof [1, 2, 3] "object" typeof true "boolean" typeof undefined "undefined" /* ======================*/ // 배열 타입 구분 Array.isArray('문자열') false Array.isArray(123) false Array.isArray([1,2,3]) true Array.isArray([]) true​ 2020. 6. 18.