【发布时间】:2021-12-23 12:37:54
【问题描述】:
我正在尝试将 .json 文件作为数组导入 Typescript,但不知道如何获取值。
import * as data from './list.json';
const array = data;
console.log(array);
我的 json 文件
[
"Element 1",
"Element 2",
"Element 3",
"Element 4",
"Element 5"
]
这就是我尝试在控制台中记录变量数组时在控制台中的样子。 我可以看到数组中的所有元素都默认存在:但我不知道如何访问它。 我已经尝试过 array[0] 并且未定义
Module
default: Array(5)
0: "Element 1"
1: "Element 2"
2: "Element 3"
3: "Element 4"
4: "Element 5"
length: 5
[[Prototype]]: Array(0)
__esModule: true
Symbol(Symbol.toStringTag): "Module"
【问题讨论】:
标签: javascript arrays json typescript