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 input is an if(Array.isArray(component))array, then just return it
//If only one element found, then convert it returninto component;a single element array anyway
if(Array.isArray(component))
else 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==isvalid__C == true){
helper.arrayfy(component.find("checkBox"))[i].set("v.value", true);
}
}
}