자바스크립트- Map함수 이용하기
·
Language/JavaScript
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; // 1번 방법 // const squared = []; // array.forEach(n=>{ // squared.push(n * n); // }) // 2번 방법: map 함수 사용하기 // const square = n => n * n; // const squared = array.map(square); // 더 간결해진 3번 방법 const squared = array.map(n => n * n); console.log(squared); 다음은 map함수로 특정 속성의 값을 꺼내오는 방법이다. const items = [ { id: 1, text : 'hello' }, { id: 2, text: 'bye' } ]; con..
takoyummy
'map' 태그의 글 목록