typescript 打字稿错误:- 类型“字符串”上不存在属性“forEach”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42618484/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:18:58  来源:igfitidea点击:

Typescript error:- Property 'forEach' does not exist on type 'string'

angulartypescript

提问by Harish Mahajan

whenever i used forEach() i got this error in terminal

每当我使用 forEach() 时,我都会在终端中收到此错误

[ts] Property 'forEach' does not exist on type 'string'.

My application works in browser properly. Everything works properly but i don't want such errors in terminal.

我的应用程序在浏览器中正常工作。一切正常,但我不希望终端出现此类错误。

I used below code for it. Please suggest me what i missing.

我使用了下面的代码。请建议我我错过了什么。

 job.forEach(function(state) {
        if((totalcarer['userId']+"")===state.rNo)
        {
          cjobState = state.cJobstatus;
        }
      });

回答by Smit

arrays: string[];
arrayString: string;

See the diff between? one is array and another is string.

看到它们之间的区别了吗?一个是数组,另一个是字符串。

arrays.forEach(...) // valid.
arrayString.forEach(...) //invalid.