How to declare a const (readonly) array in TypeScript

1 Answer

0 votes
const arr = [4, 13, 9] as const;

console.log(arr[0]);
console.log(arr[1]); 
console.log(arr[2]); 

// arr[0] = 12; // Cannot assign to '0' because it is a read-only property.

 


/*
run:
 
4 
13 
9
 
*/

 



answered Feb 27, 2022 by avibootz

Related questions

1 answer 198 views
1 answer 135 views
1 answer 135 views
1 answer 127 views
1 answer 189 views
1 answer 153 views
153 views asked Nov 23, 2020 by avibootz
...