
fetch 연습하기에서 보면,
prac3에서는 아래와 같아요.
fetch("http://spartacodingclub.shop/sparta_api/seoulair").then(res => res.json()).then(data => {
let rows = data['RealtimeCityAir']['row']
$('#names-q1').empty()
rows.forEach((a) => {
let gu_name = a['MSRSTE_NM']
let gu_mise = a['IDEX_MVL']
let temp_html = ''
if (gu_mise > 40){
temp_html = `<li class="bad">${gu_name} : ${gu_mise}</li>`
} else {
temp_html = `<li>${gu_name} : ${gu_mise}</li>`
}
$('#names-q1').append(temp_html)
})
})
반면, prac4에서는 아래와 같아요
fetch("http://spartacodingclub.shop/sparta_api/seoulbike").then(response => response.json()).then(data => {
$('#names-q1').empty()
let rows = data['getStationList']['row']
rows.forEach(a => {
let name = a.stationName
let rack = a.rackTotCnt
let bike = a.parkingBikeTotCnt
let temp_html = `<tr>
<td>${name}</td>
<td>${rack}</td>
<td>${bike}</td>
</tr>`
$('#names-q1').append(temp_html)
})
})
둘을 비교해보면, let 명령어를 써서 a안에 있는 특정 키-밸류값만 가져오게끔 할 때에, prac3에서는 a[ ], prac4에서는 a. 을 쓰는 것을 알 수 있어요.
둘 사이 차이가 있나요? 아니면 같은 기능인가요?
