Skip to main content
2 of 3
New answer

component.find() returns an array if there are more than one matches. Otherwise, it just returns that one element (and NOT an array). To avoid this situation, I almost always pass the result of my component.find() through a custom helper function that ALWAYS returns an array. Like so:

arrayfy: function(component) {
        if(Array.isArray(component)) 
            return component;
        else 
            return component? [component] : [];
    },

Use it like so:

var recordfinallist = component.get('v.attributename');                   
                for (var i = 0; i < recordfinallist.length; i++) {                       
                    if (recordfinallist[i].isvalid__C== true){                                                      
                        helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);                               
                        }                                  
                    }                                     
                }