-
看下图的代码
readonly 和 as const 都是表示固定的,包括数组和元组中的每一项不能改变。
tip:和 const参数还是有区别的。
有这样的一个场景,我需要拿到数组里面的除了第一个元素以外的值。
let arr = [1, 2, 3, 'zs', 'lisi'] as const
function Test(arr: readonly [any, ...any[]]) {
let [first, ...rest] = arr
return rest
}
console.log(Test(arr));