简体   繁体   English

Javascript 循环数组对象 N 次?

[英]Javascript loop array objects N times?

I am currently attempting to loop through an array of objects n times, but I am having trouble with the logic.我目前正在尝试循环遍历一组对象 n 次,但我在逻辑上遇到了问题。 This is my current loop:这是我当前的循环:

arrayObj.forEach(carName => console.log("looped"));

The array of object is named arrayObj where carName is a property of each object. object 的数组名为arrayObj ,其中carName是每个 object 的属性。 I want to perform this forEach n times, but I can't get something like this to work in the scenario:我想执行这个 forEach n 次,但我不能让这样的事情在场景中工作:

var times = 10;
for(var i=0; i < times; i++){
    doSomething();
}

Thanks for any input!感谢您的任何意见!

You have to use 2 loops, so you can do something like this你必须使用 2 个循环,所以你可以做这样的事情

let test = [{name:'katty'},{name:'don'},{name:'michael'}]

for(let i = 0 ;i < 10;i++) {
  test.forEach(t => {
    console.log(t);
  })
}

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

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