How to access an array of object in a loop to check if a list of checkboxes contains the id

in the blade file, i would like to iterate through the assessment_questions and check if the id is equal to the question.id, so as to set the checked to true on the checkbox.

please look for the area i added the comment //this area is where i need to access the array of object and run checks

something like {{ $parent.assessment.assessment_question.id == question.id ? checked : ‘’}}

the problem is that assessment_questions is an array of objects i.e array of questions.
Assessment Model

'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Assessment extends Model {

    assessment_evaluation_types () {
        return this.hasOne('App/Models/AssessmentEvaluationType', 'assessment_evaluation_type_id', 'id' )
    }

    assessment_questions () {
        return this.belongsToMany('App/Models/EvaluationQuestion', 'assessment_id', 'evaluation_question_id').pivotTable("assessment_questions")
        .withTimestamps()
    }

    assessment_levels () {
        return this.hasOne('App/Models/AssessmentLevel', 'assessment_level_id', 'id')
    }

    lessons () {
        return this.belongsTo('App/Models/Lesson', 'lesson_id', 'id')
    }

    fasilitator () {
        return this.belongsTo('App/Models/User', 'fasilitator_id', 'id')
    }

    application_batches () {
        return this.hasOne('App/Models/ApplicationBatch', 'application_batch_id', 'id')
    }

}

module.exports = Assessment

Assessment controller

 async showAssessment ({ view }) {

            const questions = await Question.all()
            const assessmentEvaluationTypes = await AssessmentEvaluationType.all()
            const assessmentLevels = await AssessmentLevel.all()
            const applicationBatches = await ApplicationBatch.all()
            const lessons = await Lesson.all()
            const assessments = await Assessment.query()
            .where('is_deleted', false)
            .with('fasilitator')
            .with('assessment_evaluation_types')
            .with('lessons')
            .with('assessment_levels')
            .with('application_batches')
            .with('assessment_questions')
            .fetch();
      
       return view.render('admin.assessment_list', {
            assessments:  assessments.toJSON(),
            questions: questions.toJSON(),
            assessmentTypes: assessmentEvaluationTypes.toJSON(),
            assessmentLevels: assessmentLevels.toJSON(),
            applicationBatches: applicationBatches.toJSON(),
            lessons: lessons.toJSON()
       });
   }

most important part of the edge file

@each(assessment in assessments)

{{--edit applicant interaction modal  --}}
  <div id="edit-assessment-{{assessment.id}}" class="modal fade effect-slide-in-bottom">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content modal-content-demo">
        <div class="modal-header">
          <h6 class="modal-title"><strong>Edit Assessment</strong></h6>
        </div>
        <form >
          <div class="modal-body">
             <div class="col">
                            <div class="form-group mt-4">
                                <label for="formGroupExampleInput"><h5>Assessment Title</h5></label>
                                <input name="assessment_title" type="text" value="{{ assessment.assessment_title }}" class="form-control" required data-parsley-error-message="Please specify current assessment title" placeholder="Assessment title please">
                                @if(hasErrorFor('assessment_title'))
                                    <small class="help-block error-messages">{{ getErrorFor('assessment_title') }}</small>
                                @endif
                            </div>
                            <div class="row justify-content-between">
                                    <div class="col-md-4">
                                        <label class="font-weight-bold" for="">Assessment Type</label>
                                        <select class="custom-select "  name="assessment_evaluation_type_id" id="assessment_evaluation_type" required data-parsley-error-message="Please specify current assessment type">
                                        @if(assessmentTypes)

                                            @each(assessmentType in assessmentTypes)
                                                <option value="{{ assessmentType.id }}" {{  assessmentType.id == $parent.assessment.assessment_evaluation_type_id  ? 'selected' : '' }} > {{assessmentType.type}}</option>
                                            @endeach
                                        @endif
                                        </select>
                                         @if(hasErrorFor('assessment_evaluation_type_id'))
                                            <small class="help-block error-messages">{{ getErrorFor('assessment_evaluation_type_id') }}</small>
                                         @endif
                                    </div>
                                    <div class="col-md-4">
                                        <label class="font-weight-bold" for="">Assessment Level</label>
                                        <select class="custom-select " name="assessment_level_id" id="assessment_level" required data-parsley-error-message="Please specify current assessment level">
                                            @if(assessmentLevels)
                                                @each(assessmentLevel in assessmentLevels) 
                                                    <option value="{{ assessmentLevel.id }}" {{  assessmentLevel.id == $parent.assessment.assessment_level_id  ? 'selected' : '' }} > {{assessmentLevel.type}}</option>
                                                @endeach
                                            @endif
                                        </select>
                                        @if(hasErrorFor('assessment_level_id'))
                                            <small class="help-block error-messages">{{ getErrorFor('assessment_level_id') }}</small>
                                         @endif
                                    </div>
                                    <div class="col-md-4">
                                        <label class="font-weight-bold" for="">Set Timer</label>
                                        <select class="custom-select " name="end_time" required data-parsley-error-message="Please specify duration of assessment">
                                           @if(assessmentTypes)

                                                    <option value="5 Mins" > 5 Mins</option>
                                                    <option value="10 Mins" > 10 Mins</option>
                                                    <option value="15 Mins" > 15 Mins</option>  
                                            @endif
                                        </select>
                                         @if(hasErrorFor('end_time'))
                                            <small class="help-block error-messages">{{ getErrorFor('end_time') }}</small>
                                         @endif
                                    </div>   
                                </div>
                                
                                <div class="row  align-items-center mt-4 justify-content-between">
                                    <div class=" col-md-3  ">
                                        <a data-toggle="modal" data-target="#exampleModalLong" id="addBtn" style="background: #343640; border-radius: 20px" class="btn text-white btn-primary">Add Questions</a>
                                         <small id="addBtnError" class="help-block error-messages"></small>
                                    </div>
                                    <div class=" col-md-3  ">
                                       <label class="font-weight-bold" for="additional_marking">Addition Marking</label>
                                        <select class="custom-select " name="additional_marking" id="additional_marking"  required data-parsley-error-message="Please specify the applicable batch">
                                           @if(applicationBatches)
                                                <option value="1"   > true</option>
                                                <option value="0" > false</option>
                                            @endif
                                        </select>
                                    </div>
                                    <div class="col-md-4">
                                        <label class="font-weight-bold" for="application_batch">Select Applicable Batch</label>
                                        <select class="custom-select " name="application_batch_id" id="application_batch" required data-parsley-error-message="Please specify the applicable batch">
                                           @if(applicationBatches)
                                                <option label="Choose one"></option>
                                                @each(applicationBatch in applicationBatches)
                                                    <option value="{{ applicationBatch.id }}"  {{ applicationBatch.id == $parent.assessment.application_batch_id ? 'selected' : '' }}  > {{applicationBatch.batch_title}}</option>
                                                @endeach
                                            @endif
                                        </select>
                                        @if(hasErrorFor('application_batch_id'))
                                            <small class="help-block error-messages">{{ getErrorFor('application_batch_id') }}</small>
                                         @endif
                                        <input type="hidden" name="fasilitator_id" value="{{auth.user.id}}"/>
                                    </div>
                                    
                                </div>
                                <div class="">
                                        <label class="font-weight-bold" for="lesson">Select Lesson</label>
                                        <select class="custom-select " name="lesson_id" id="lesson" required data-parsley-error-message="Please specify the applicable lesson">
                                           @if(lessons)
                                                <option label="Choose one"></option>
                                                @each(lesson in lessons)
                                                    <option value="{{ lesson.id }}" {{lesson.id == $parent.assessment.lesson_id ? 'selected' : '' }}  > {{lesson.title}}</option>
                                                @endeach
                                            @endif
                                        </select>
                                        @if(hasErrorFor('lesson_id'))
                                            <small class="help-block error-messages">{{ getErrorFor('lesson_id') }}</small>
                                         @endif
                                
                                    </div>
                                

                                <div class="mt-4">
                                    <button type="submit" onclick=" event.preventDefault(); validateQuestions()"  style="background: darkblue; border-radius: 20px" class="btn btn-success btn-block">   
                                        Update Assessment
                                    </button >
                                </div>

                            </div>
                        </div>
                    </div>
                  </form>
                </div>
              </div>
            </div>

            <div class="modal fade" id="exampleModalLong"  tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true">
           
            <div class="modal-dialog" role="document">

                <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title mx-auto" id="exampleModalLongTitle">Please Select Questions</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                  
                    <div class="modal-body" style="max-height: 400px; overflow-y: scroll">
                        <div class="col">
                            <div class="col align-content-center ">
                                @if(questions)
                                    
                                    @each(question in questions)  
                                        <div style="border-bottom: 1px solid #eee" class="col-md-12  mb-5 row">
                                            <h4>{{question.question_title}}</h4>
                                                <div class="form-check form-check-inline   row col-lg-8 col-md-8"> 
                                                <label class="form-check-label mx-1 " for="inlineCheckbox{{$loop.index + 1}}">{{$loop.index + 1}}</label>
              //this area is where i need to access the array of object and run checks                                
                                                <input name="evaluation_question_id" class="form-check-input checks mx-1" value={{question.id}} type="checkbox" {{$parent.assessment.assessment_question.id == question.id ? checked : ''}}  id="inlineCheckbox{{$loop.index + 1}}" value="option1">
                                                <label class="form-check-label col-md-10 " for="inlineCheckbox{{$loop.index + 1}}"> {{question.question_text}} </label>
                                            </div>
                                            <div  class="question-image  col-md-3 col-lg-3">
                                                <img  style="max-width: 100%" src="https://i.ibb.co/WyQCHn4/IMG-20180107-095559-095.jpg"/>
                                            </div> 
                                        </div>
                                    @endeach
                                @else
                                    <div>No available Questions</div>
                                @endif
                            </div>
                        </div>
                    </div>
                 
            
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <button type="button" data-dismiss="modal" class="btn btn-primary">Save changes</button>
                </div>
                </div>
            </div>
        </div>
      @endeach      

structure of the data

[  { id: 8,
    assessment_title: 'New Question',
    assessment_evaluation_type_id: 1,
    assessment_level_id: 1,
    lesson_id: 3,
    additional_marking: 1,
    fasilitator_id: 1,
    application_batch_id: 1,
    start_time: '0',
    end_time: '5 Mins',
    is_deleted: 0,
    created_at: '2019-06-02 13:21:42',
    updated_at: '2019-06-02 13:21:42',
    fasilitator:
     { id: 1,
       first_name: 'Adegbenga',
       last_name: 'Agoro',
       email: 'adegbenga@designsbycrenet.com',
       password:
        '$2a$10$QhSLG86V8FcR/MqqqBgpXewI.C/3E4oMsZ1ZOByH86qmMOQBDJkty',
       profile_picture: null,
       user_role: 'Crenet Admin',
       confirmation_token: null,
       is_active: 'Active',
       created_by: 0,
       modified_by: null,
       is_deleted: 0,
       deleted_by: null,
       created_at: null,
       updated_at: null },
    assessment_evaluation_types:
     { id: 1, type: 'Assignment', created_at: null, updated_at: null },
    lessons:
     { id: 3,
       title: 'Zalum ro piz wofnub jomig ro cungokas geeb.',
       module_id: 6,
       track_id: 12,
       description:
        'Jonicfu catlaz bidluw odtiz udeolij piatfo bivjat zuima cik nekkuoso mekgum pa wa lihebro jogad esoju pozacota bor. Giz souje zuvseak ribli utcace jacve owwiz giudu kigafzab wivcawlap parec po azhemefu vafob jehkekwu doicul. Nohhekar so pigibuku kecib wo uswed gihnur paoj zim viv nubepvoz dal.',
       content:
        'Urafu ekgorop ha ujatzi varijij hez vozisowe tep po docorkac juzwopad mabufo sa kom okhihluc. Pepjarni utzones migepjic jingun urepeduj ac injuwa vusruseb semar iduok acociwu avesasov. Hawif caijoduz ijobi on ig maz jivviwu judci acsuwe cimibpe duufumic te ukase afhe ju me gudgedi. Cerin saabji kej puj gor nepir aliuv epuan bikeg va ko egecechub luk viub ilpur. Kicew nap godes vagsoluf izoefi seketped tewbim wencef usa oc amcede te hujzev azu sodu. Defastiz de wobwoow ati leaviwed fohsefec ke loeh bu itiebpu dit hacitok ri sule tep. Kuc ziprep kepamac udaved ewtidup otemazcup walimnav re cehuspib mewuzih ajanachut he ip mikledvi. Asitec if calat suzu ce uzubojde lifechuv mophiwhum roduhe oredelam nu ket ikida joegmef. Guka pu lo ce lo vuwla zul duw caagu cawe pavusew jale. Biceh ucez sihizlo ijore haot gidse fab weige foap cicudop bapeli poaswij bun ji dubni.',
       user_id: 13,
       cover_image_url: 'http://zabad.es/guc',
       created_at: '2019-05-30 19:51:54',
       updated_at: '2019-05-30 19:51:54' },
    assessment_levels:
     { id: 1, type: 'Course', created_at: null, updated_at: null },
    application_batches:
     { id: 1,
       batch_title: 'SCV-B0002',
       batch_start_date: 2019-03-24T23:00:00.000Z,
       batch_end_date: 2019-04-09T22:00:00.000Z,
       batch_status: 'Active' },
    assessment_questions: [ [Object], [Object] ] },
  { id: 9,
    assessment_title: 'hello',
    assessment_evaluation_type_id: 1,
    assessment_level_id: 1,
    lesson_id: 2,
    additional_marking: 0,
    fasilitator_id: 1,
    application_batch_id: 1,
    start_time: '0',
    end_time: '5 Mins',
    is_deleted: 0,
    created_at: '2019-06-03 14:47:55',
    updated_at: '2019-06-03 14:47:55',
    fasilitator:
     { id: 1,
       first_name: 'Adegbenga',
       last_name: 'Agoro',
       email: 'adegbenga@designsbycrenet.com',
       password:
        '$2a$10$QhSLG86V8FcR/MqqqBgpXewI.C/3E4oMsZ1ZOByH86qmMOQBDJkty',
       profile_picture: null,
       user_role: 'Crenet Admin',
       confirmation_token: null,
       is_active: 'Active',
       created_by: 0,
       modified_by: null,
       is_deleted: 0,
       deleted_by: null,
       created_at: null,
       updated_at: null },
    assessment_evaluation_types:
     { id: 1, type: 'Assignment', created_at: null, updated_at: null },
    lessons:
     { id: 2,
       title: 'Nejwokiw set ker oc ewumu rarlezup em mivvu.',
       module_id: 4,
       track_id: 8,
       description:
        'Ew bugease kul putu upalmo uta ha ku pi ivecovbe nena tej vub ivatog. Lav depemor cuomseg ma inoidozo owa saepu mobek posiruh jeppa ogaveka ehezik. Rumumugag ege tuwuzgi jorkibuvi uv fa rum bevamuk hibha iplicen hu pale wear eplassoj dut.',
       content:
        'Ducco ki mahdufse ibi esigi nucar zub nirok vonsewu jorpibfu uctiso cewbog dacutbi ma tosulisik lem dulu ku. Kipehupo aseoh rifmobal sivtip curni habih foprefhu nehifas poga ile kaf pudjakek duzol pu nuzif hola. Cag gejlegez avuhi cuwgudo ku tokowit bape imakopul vav ubfimi soc cacde ra usouma nem widke. Biiw vulig enper den muwar ta cuuv kuta nizeev utu tapjavhid urfaoc zi ser bibi covim. Ed socrulrir to ijere jasgo wijojjin geceti bop nulhesa teb tikoguv lu mub asiupda. Guif jidverwe nezuw gonej nac uho awewate ojuf seeco nuw huf pemgujva fepomug. Tep bupigha od fiv sismuga fa famlatabo upima hik barzi ka vaj. Fekbutfe lineobo edbir vuomuc soocve gap kikho agjauwu relaw jal fin uzaja bir epe sidtol hispu ipa fo. Tepuri re mucegoera lulfe tec an futig wu uz ivisiven lo uzvaw lorrobeco diju. Siv giru zovtejeh puvi wis feenjel cigzuwav habtaddu kitakeeto fugo eseemoefa binazlel.',
       user_id: 11,
       cover_image_url: 'http://rimajoke.lb/nobon',
       created_at: '2019-05-30 19:51:52',
       updated_at: '2019-05-30 19:51:52' },
    assessment_levels:
     { id: 1, type: 'Course', created_at: null, updated_at: null },
    application_batches:
     { id: 1,
       batch_title: 'SCV-B0002',
       batch_start_date: 2019-03-24T23:00:00.000Z,
       batch_end_date: 2019-04-09T22:00:00.000Z,
       batch_status: 'Active' },
    assessment_questions: [ [Object], [Object] ] } ,...]
1 Like