相关疑难解决方法(0)

获取JavaScript数组中的所有唯一值(删除重复项)

我有一系列数字,我需要确保它们是唯一的.我在互联网上找到了下面的代码片段,它的工作情况很好,直到数组中的数字为零.我发现这个其他脚本在SO上看起来几乎就像它,但它不会失败.

所以为了帮助我学习,有人可以帮我确定原型脚本出错的地方吗?

Array.prototype.getUnique = function() {
 var o = {}, a = [], i, e;
 for (i = 0; e = this[i]; i++) {o[e] = 1};
 for (e in o) {a.push (e)};
 return a;
}
Run Code Online (Sandbox Code Playgroud)

重复问题的更多答案:

类似的问题:

javascript arrays unique

1273
推荐指数
40
解决办法
122万
查看次数

错误 TS2305:模块“react”没有导出成员“Node”

我运行了 React Native 项目以及官方文档,并将 TypeScript 添加到了该项目中。当我执行“yarn tsc”时,发生了许多 ESlint 错误,例如:

App.tsx:10:14 - error TS2305: Module '"react"' has no exported member 'Node'.

10 import type {Node} from 'react';
Run Code Online (Sandbox Code Playgroud)

我知道这只是一个 TS 错误,但我很困惑,为什么代码“import type {Node} from 'react';”会产生此错误

tsconfig.json:

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "isolatedModules": true,
    "jsx": "react-native",
    "lib": ["es2017"],
    "moduleResolution": "node",
    "noEmit": true,
    "strict": true,
    "target": "esnext"
  },
  "exclude": [
    "node_modules",
    "babel.config.js",
    "metro.config.js",
    "jest.config.js"
  ]
}
Run Code Online (Sandbox Code Playgroud)

typescript reactjs react-native

13
推荐指数
2
解决办法
9766
查看次数

标签 统计

arrays ×1

javascript ×1

react-native ×1

reactjs ×1

typescript ×1

unique ×1