커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
fetch에서 막히는 부분이 있습니다. :) bbb
코딩이 처음이어도 쉽게 배우는 웹개발 A to Z
챕터 3
북마크
이*호
댓글
6
추천
0
조회수
22
조회수
22
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.



스파르타 즉문즉답


여기 부분을 보면

  let rows = data['RealtimeCityAir']['row'];

를 설정안해도 값들이 출력 되는 데,


아래 1) , 2)는 값들이 출력되지 않는 이유가 있을까요???



1)

        function hey() {
            let url = 'http://spartacodingclub.shop/sparta_api/seoulair';
            fetch(url).then(res => res.json()).then(data => {
                data.forEach(a => {
                    let gu_name = a['MSRSTE_NM'];
                    let gu_mise = a['IDEX_NM'];
                    console.log(gu_name, gu_mise);
                });
            })
        }


결과 :

prac2.html:12

Uncaught (in promise) TypeError: data.forEach is not a function

at prac2.html:12:22



2)

        function hey() {
            let url = 'http://spartacodingclub.shop/sparta_api/seoulair';
            fetch(url).then(res => res.json()).then(data => {


                data.forEach(a => {
                    console.log(a['MSRSTE_NM'], a['IDEX_NM']);
                });
            })
        }


결과 :


prac2.html:13

Uncaught (in promise) TypeError: data.forEach is not a function

at prac2.html:13:22








3)

        function hey() {
            let url = 'http://spartacodingclub.shop/sparta_api/seoulair';
            fetch(url).then(res => res.json()).then(data => {
                let rows = data['RealtimeCityAir']['row'];
                rows.forEach(a => {
                    let gu_name = a['MSRSTE_NM'];
                    let gu_mise = a['IDEX_NM'];
                    console.log(gu_name, gu_mise);
                });
            })
        }



결과 :

스파르타 즉문즉답









스파르타 즉문즉답






취소
 공유
취소
댓글 0
댓글 알림
나의얼굴