Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Angular 2:Array.find不是函数_Arrays_Angular_Typescript - Fatal编程技术网

Arrays Angular 2:Array.find不是函数

Arrays Angular 2:Array.find不是函数,arrays,angular,typescript,Arrays,Angular,Typescript,调用此函数时,它返回以下错误:this.selected.find不是函数 我怎样才能解决这个问题 编辑: typescript版本是2.0.10 tsconfig文件: select(object: Mill | Paver | Vehicle) { if (!this.selected.find(o => o.object === object)) { if (object instanceof Paver || object instanceof Vehicl

调用此函数时,它返回以下错误:this.selected.find不是函数

我怎样才能解决这个问题

编辑:

typescript版本是2.0.10

tsconfig文件:

select(object: Mill | Paver | Vehicle) {
    if (!this.selected.find(o => o.object === object)) {
        if (object instanceof Paver || object instanceof Vehicle) {
            this.selected.push(this.getTripsFromPlanning(object));
        } else {
            this.selected.push({
                object: object,
                marker: this.mapService.addMarker(object.location, object.name, false, 0)
            });
        };
    }
}

显然,
此。选定的
不是数组。您是否尝试过
console.log(this.selected)
以了解
this.selected
实际上是什么?在angular 2中,您必须使用Array.filter而不是Array.find.what?您也可以在angular2中使用Array.find。为什么这应该与angular2控制台相关。log(this.selected)不会返回任何明显的
信息。selected
不是数组。您是否尝试过
console.log(this.selected)
以了解
this.selected
实际上是什么?在angular 2中,您必须使用Array.filter而不是Array.find.what?您也可以在angular2中使用Array.find。为什么这应该与angular2控制台相关。log(this.selected)不返回任何内容
select(object: Mill | Paver | Vehicle) {
    if (!this.selected.find(o => o.object === object)) {
        if (object instanceof Paver || object instanceof Vehicle) {
            this.selected.push(this.getTripsFromPlanning(object));
        } else {
            this.selected.push({
                object: object,
                marker: this.mapService.addMarker(object.location, object.name, false, 0)
            });
        };
    }
}
{
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "suppressImplicitAnyIndexErrors": true,
    "lib": ["es6", "dom"],
    "mapRoot": "./",
    "module": "es6",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc",
    "sourceMap": true,
    "target": "es6",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }
}