
토이프로젝트에 댓글 수 기능을 추가할려고 하고있는데 'rows'의 마지막 index에 있는 값을 쓰고 싶어요! 파이썬 처럼 rows[-1] 했는데 안되더라고요. rows[]안에 뭐가 들어가야지 마지막 index에있는 value를 쓸 수 있을까요? 감사합니다!
$.ajax({
type: "GET",
url: "/comment",
data: {},
success: function (response) {
let rows = response['comments']
let total_comment = rows[]['total_comment'] //<<<<이줄에 rows[ ] 안에 들어가야돼는 숫자알려주세요 ㅜㅜ
let temp_html2 = `<i class='fas fa-comment-dots'>${total_comment}</i>`
$('#icon').append(temp_html2)
}
});
작성한 코드 및 에러 메세지
$.ajax({
type: "GET",
url: "/comment",
data: {},
success: function (response) {
let rows = response['comments']
let total_comment = rows[]['total_comment'] //<<<<이줄에 rows[ ] 안에 들어가야돼는 숫자
let temp_html2 = `<i class='fas fa-comment-dots'>${total_comment}</i>`
$('#icon').append(temp_html2)
}
});
해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
