简体   繁体   English

如何在angular4中使用每个

[英]how to use for each in angular4

i have a doubt, i have 2 arrays 我有一个疑问,我有2个数组

A=[2,2,3];

在此处输入图片说明

i create both array by pushing values .but when i use second array with foreach i didn't get values to display. 我通过推值来创建两个数组。但是当我将第二个数组与foreach一起使用时,我没有显示值。

b.foreach((test,index)=>{
   console.log(test+"_0");
  }
)

i am using this format for extract values. 我正在使用这种格式提取值。 is it is wrong ? 是错的吗? need to change anything? 需要改变什么吗?

With angular and Typescript you need to use as, 使用angular和Typescript时,您需要用作

for (let item of this.data) { 
    console.log(item +"_0");
}  

DEMO

forEach is always be in camelCase, forEach总是在驼峰下,

See this, 看到这个

b.forEach((test,index) =>{
   console.log(test+"_"+index);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM