딸기가 총 몇 개인지 알 수 있는 방법.
다음 두 가지 방식의 결과는 같다. 첫 번째는 기존의 방식, 두 번째는 React에서 잘 쓰는 방식.
첫 번째,
let fruit_list = ['사과','감','감','배','포도','포도','딸기',
'포도','감','수박','딸기']
let count = 0;
for(let i=0; i<fruit_list.length; i++){
if(fruit_list[i]=='딸기'){
count+=1;
}
}
console.log(count);
두 번째,
let fruit_list = ['사과','감','감','배','포도','포도','딸기',
'포도','감','수박','딸기']
let count = 0;
fruit_list.map((value, i) => {
if(fruit_list[i]=='딸기'){
count+=1;
}
})
console.log(count);
LIST
'Computer Programming > React-Native' 카테고리의 다른 글
(React-Native) Project: TabNavigator 기능 넣기 (0) | 2022.08.15 |
---|---|
(React-Native) Project: Create Project & StackNavigator 기능 넣기 (0) | 2022.08.15 |
React-Native App 개발(Page와 Component 만들기) (0) | 2022.07.18 |
React-Native App 개발(component 이용한 counter 만들기) (0) | 2022.07.05 |
앱개발 종합반_filter (0) | 2022.06.27 |