let entry: [number, string, boolean] = [42, "蓝色天空网", true];
console.log(entry[0], entry[1], entry[2]);
entry[0] = 121; const [id, title] = entry;
console.log(id, title);
const extra: [boolean, number] = [false, 100];
const combined: [number, string, boolean, boolean, number] = [...entry, ...extra];
console.log(combined.slice(1).join(","));
const copy = Array.from(entry); copy.push("新项"); console.log(copy.join(","));
const removed = entry.pop(); console.log(removed, entry.length);
本例需在 固定版本的TypeScript编译器,启用strict;编译产物在支持ES2022的JavaScript环境中运行 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:固定版本的TypeScript编译器,启用strict;编译产物在支持ES2022的JavaScript环境中运行
入口文件:examples/a288147a7ee8850e6538cd8b/core/core.ts
预期结果与验证条件观察提示
- 初始42、蓝色天空网、true;更新后121、蓝色天空网
- 连接后slice序列蓝色天空网,true,false,100
- 普通数组副本121,蓝色天空网,true,新项
- pop实际移除true,运行时length=2;之后不读取原第三位置
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联72章) · 含当前章节或实例 · mbskycom202611a325.zip