I have an array of empty objects like this:
var a = [ {}, {}, {}, {}, {}, {} ];
And an array of properties:
var colors = ["red", "green", "blue"];
I need to assign each color in "colors" to every element of "a" array with angular foreach. But the length of "a" array is greater than "colors". I want to assign the colors "by circle" So the result needs to be like this:
var a = [
{color: "red"},
{color: "green"},
{color: "blue"},
{color: "red"},
{color: "green"},
{color: "blue"},
{color: "red"}
];
angular.forEach(a, function(elem, index) {
if (a.length > colors.length) {
// .......
}
elem.color = colors[index];
});
The question: Is there some way to reset the index of foreach to start looping the "colors" array from beginning? Thanks for help
elem.color = colors[index % colors.length];