Как использовать переменную в имени функции?

Я хочу создать функцию по количеству записей в таблице.

<script>
    console.log({{count_id.id}})
    for (let i = 1; i =< {{count_id.id}}; i++) {
        num = i
        function attendance_present + num() {
            document.querySelector('#present').textContent = "Present"
            document.querySelector('#present').classList.remove("btn-outline-danger")
            document.querySelector('#present').classList.remove("btn-outline-warning")
            document.querySelector('#present').classList.add("btn-outline-primary")
        }

        function attendance_absent + num() {
            document.querySelector('#present').textContent = "Absent"
            document.querySelector('#present').classList.remove("btn-outline-primary")
            document.querySelector('#present').classList.remove("btn-outline-warning")
            document.querySelector('#present').classList.add("btn-outline-danger")
        }

        function attendance_half_day + num() {
            document.querySelector('#present').textContent = "Half-day"
            document.querySelector('#present').classList.remove("btn-outline-primary")
            document.querySelector('#present').classList.remove("btn-outline-danger")
            document.querySelector('#present').classList.add("btn-outline-warning")
        }
    }
</script>

появление {{count_id.id}} из представлений в django.

Вернуться на верх