728x90
반응형
map()
JavaScript의 표준 내장 객체 Array의 메소드 prototype.map()이다.
배열 내의 모든 요소 각각에 대하여 주어진 함수를 호출한 결과를 모아 새로운 배열을 반환한다.
형식
arr.map(callback(currentValue[, index[, array]])[, thisArg])
Ex01.
import { useState } from "react";
const IterationSample = () => {
const names = ['눈사람', '호빵', '눈', '바람'];
const nameList = names.map(
(currentValue, index, array) =>
<li>
<p>currentValue={currentValue}</p>
<p>index={index}</p>
<p>array={array}</p>
</li>
);
return (
<ul>
{nameList}
</ul>
)
}
export default IterationSample;
참고자료
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/map
728x90
반응형
'Front-End > REACT' 카테고리의 다른 글
[REACT] Sass (0) | 2022.12.09 |
---|---|
[REACT] 라이브러리 (0) | 2022.12.09 |
[REACT] list 추가, 삭제 - map, concat, filter (0) | 2022.12.08 |
[REACT] input 클릭이벤트 (0) | 2022.12.07 |
[VSCode] 유용한 확장프로그램 (0) | 2022.12.05 |
댓글