Home > other >  Transforming null into array.length = 0
Transforming null into array.length = 0

Time:04-08

Probably a noob Question: On my server, there is a filter which returns all available options if an array of the filter object has length.0 for certain options.

Now if say i have an input "All Options" from the user side, this option when clicked must somehow tell the array to have length.0, so the server returns all options . I tried to set the Input to

  <mat-option [value]= null >Alle</mat-option> 

But that results in an array that has the value null instead of no length at all.

I also tried

If (data.array[1] == undefined){
data.array.length == 0
}

But that did not work

CodePudding user response:

Leave the value to null and then do it like this:

if (!data.array) {
    data.array = [];
}
  • Related