0

I have a function that has a menu param

removeChildCheck:function(menu){
    let removeArrayValues = [];
       for(var i=0; i < this.checkbox.menu.length; i++){
           removeArrayValues.push(this.checkbox.menu[i].value);
       }
       this.user.permissions = this.user.permissions.filter((i) => !removeArrayValues.includes(i));
 },

when I used it like this removeChildCheck('dashboard') im getting length of undefined.

How can I append the param and loop on it? TIA

2 Answers 2

1

Do you mean to do:

this.checkbox[menu]

That is, access the property of checkbox that has the name stored in the variable menu? Keep in mind that:

this.checkbox.dashboard

is equivalent to

this.checkbox['dashboard']

and

menu = 'dashboard'
this.checkbox[menu]
Sign up to request clarification or add additional context in comments.

Comments

1

As audiodude says, use array syntax: this.checkbox[menu].length

removeChildCheck:function(menu){
    let removeArrayValues = [];
       for(var i=0; i < this.checkbox[menu].length; i++){
           removeArrayValues.push(this.checkbox[menu][i].value);
       }
       this.user.permissions = this.user.permissions.filter((i) => !removeArrayValues.includes(i));
 },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.