반응형
250x250
Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- realtimesystem
- 자동차sw
- 암호화폐
- python
- 블록체인
- 퀀트
- toefl writing
- 파이썬
- 아마존 웹 서비스
- it
- 클라우드
- Cloud
- 토플
- 확률
- 프로그래밍
- AUTOSAR
- 오토사
- backtrader
- 임베디드
- probability
- GeorgiaTech
- 토플 라이팅
- AWS
- can
- 개발자
- 실시간시스템
- TOEFL
- 비트코인
- 자동매매
- 백트레이더
Archives
- Today
- Total
Leo's Garage
JavaScript - map으로 Array Data Rendering 본문
728x90
반응형
JavaScript로 코드를 작성하다보면, Array 형태의 Data를 순차적으로 Rendering해야하는 상황을 만나게 된다.
그때는 map을 사용해서 Rendering할 수 있다.
import React from 'react';
import { View, Text } from 'react-native';
const MyFunctionalComponent = (props) => {
const data = props.data;
const arraySize = data.length;
return (
<View>
<Text>Array size: {arraySize}</Text>
{data.map((item, index) => {
return (
<Text key={index}>{item}</Text>
);
})}
</View>
);
};
export default MyFunctionalComponent;
위에 예제 코드를 살펴보면, data가 array형태로 props를 통해 전달받은 것이다.
해당 data의 각 element들을 Rendering할 때는 위 처럼 map(item,index)로 쓴다.
여기서 index는 array의 index이다.
보통 Rendering할 때는 key={index}를 써준다.
728x90
반응형