Home > Back-end >  how to convert a string array to a boolean array in typescript
how to convert a string array to a boolean array in typescript

Time:11-29

I have a list of objects that gets returned from the font end as

item=["false","true"]

i take these items to check a column from my records to see which values contain true or false as follows

this.records.filter(x=> items.includes(x.column))

but my records are always returning empty.

if i hard code it as example this.records.filter(x=> x.column == false) it works.

But i am using includes() because a user can select both true or false options and i cant go hard code it cause i wont know what the user might select.

how do i convert the string ["true","false"] into [true,false]?

i tried declaring items as

public items:boolean[]=[];

but still no luck

CodePudding user response:

You can convert it using items.map(item => item === "true")

  • Related