How can I Convert a ReadonlyArray<any> to any[]?

Viewed 6542

Some native angular functions return a ReadonlyArray. Some native angular callbacks pass ReadonlyArrays. Since my typescript code may be called in many ways, I don't want to require all arrays passed to my functions be ReadonlyArrays.

Hence I need to convert a ReadonlyArray to a javascript native array, [].

1 Answers

The simplest way to convert the ReadonlyArray to any[] is to use one of the available methods of ReadonlyArray.

For this we will use concat(). Calling concat with no parameters on a ReadonlyArray will return an [].

You can view other ReadonlyArray members here.

Related