Skip to content
Advertisement

converting an array into object in typescript

I have an array of objects:

JavaScript

Where

JavaScript

I need to convert it to the type NFCollection which looks so:

JavaScript

The result should looks like this:

JavaScript

where the data includes only those persons whose age >= 18.

So I could start writing something like:

JavaScript

but then I would like to convert it to the NFCollection type. How would I do that? Preferably in a memory efficient way, cos the array could be relatively big.

Advertisement

Answer

Just put the filtered array as a property of a new object?

JavaScript

Then nfCollection will have the same type as your NFCollection interface.

Advertisement