Home > Enterprise >  how to check the array element is empty in typescript
how to check the array element is empty in typescript

Time:02-22

how to check array element is empty. its giving false. how to get the element is blank or not. in array element contains some space.

Code

let TestNumber= DATA-   -    -'
let arrStr =this.TestNumber.split(/[-]/);
if(arrStr[1]==''){
}

output -false

expected op - true;

 data - ['DATA', '   ', '    ', '']

CodePudding user response:

You need to .trim() the whitespace for each element.

let arrStr = TestNumber.split(/[-]/).map(x => x.trim());

let TestNumber= 'DATA-   -    -';
let arrStr = TestNumber.split(/[-]/).map(x => x.trim());
console.log(arrStr[1] == "");

  • Related