我想使用set函数将一个数组的唯一值转换为一个单独的数组。这是我的代码:
import { readFileSync } from 'fs';
import { Table } from 'apache-arrow';
const arrow = readFileSync('file.arrow');
const table = Table.from(arrow);
const table_array = table.toArray();
var values : string[] = [];
for(let i = 0; i < table_array.length; ++i){
var str = table_array[i][1]
var id_val = str.toString().split('.');
values.push(id_val[6]);
}
var unique_id = [...new Set(values)];
console.log(values)这是我得到的错误:
error TS2569: Type 'Set<string>' is not an array type or a string type.
var unique_id = [...new Set(values)];这是控制台输出。我不得不隐藏这些值,但它们是字符串格式的数字:
[
'####', '####', '####', '####', '####',
'####', '####', '####', '####', '####',
'####', '####', '####', '####', '####',
'####', '####', '####', '####', '####',
... 427 more items
]发布于 2021-04-15 16:40:33
将此downlevelIteration属性设置为tsconfig.json文件,以允许按照编辑器的建议迭代可迭代对象
{
"compilerOptions": {
...
"downlevelIteration": true
...
}
}https://stackoverflow.com/questions/67104665
复制相似问题