Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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, [].

like image 318
N-ate Avatar asked Jan 14 '19 20:01

N-ate


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.

like image 113
N-ate Avatar answered Nov 18 '22 11:11

N-ate