I currently have an array of objects called memberToChange.checkboxes: ICheckbox[] structured like this:
https://i.stack.imgur.com/LyKVv.png
Within this setup, there is also a variable named internalNumber with the value "3419". My objective is to locate the object within the array where the label property matches the internalNumber. Once located, I aim to set the value attribute of that specific object to true.
The code snippet I am using for this task is as follows:
let checkboxes = _.find(scope.selectedMembers, (member: IMember) => member.member.uuid === memberId).checkboxes; //returns an array of checkboxes
let checkboxToChange = _.find(memberToChange.checkboxes, function(checkbox: ICheckbox){
return (checkbox.label === internalNumber);
}); //this seems to be returning null, and even a console.log statement inside the second find does not execute. It appears that the two consecutive _.find statements might be causing some interference, although I'm uncertain about the root cause.
For further context, below is the definition for my ICheckbox interface:
export interface ICheckbox {
label: string;
sublabel?: string;
value: boolean;
numberUuid: string;
}
Expectations were that for internalNumber 3419, the second object from the array would be returned. However, instead of that expected result, undefined is returned. This issue has left me confused. If you have an alternative approach that can efficiently identify and update the value to true in a single operation, I would greatly appreciate your feedback. Thank you for any assistance.
Update:
Upon receiving a suggestion to leverage the filter method in JavaScript, I attempted the following implementation:
scope.selectedMembers.filter(function(member) {
if (member.member.uuid === memberId) {
scope.memberCheckboxes = [];
console.log('found member'); //prints
scope.memberCheckboxes = member.checkboxes;
console.log(scope.memberCheckboxes); // prints correctly, displaying the checkboxes associated with the member
scope.memberCheckboxes.filter(function(checkbox) {
console.log('inside checkbox function'); //control doesn't reach here
if (checkbox.label === intNum) {
console.log('found checkbox'); // control doesn't reach here
}
});
}
});
Confusion arises when the initial console.log statement inside the scope.memberCheckboxes.filter function fails to display. Is there something glaringly obvious that I may have overlooked?