개발/javascript & jquery
fetch , then 내림차순 오름차순
멋진놈
2022. 11. 8. 11:17
728x90
fetch('/api/v1/book/'+id).then(response => {
console.log('response-opinion', response);
if (response.ok) {
return response.json();
}
}).then(json => {
console.log(json, "json");
let html = '';
if (!json.length) {
html = '<td colspan="5">등록된 책이 없습니다.</td>';
} else {
json.forEach((obj, idx) => {
console.log(obj, "obj");
html += `
<td style="text-align: center;"><span class="event-td-font">${json.length - idx}</span></td>
`;
})
}
});
에서
# 내림차순
${json.length - idx}
# 오름차순
${idx + 1}