点击运行
function createArray
(length: number, value: T): Array
{ let result: T[] = []; for (let i = 0; i < length; i++) { result[i] = value; } return result; } console.log(createArray
(3, 'x')); // ['x', 'x', 'x']
运行结果 :
正在执行...