javascript loop arrays code example
Example 1: javascript code to loop through array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 2: loop array javascript
var colors = ['red', 'green', 'blue'];
colors.forEach((color, colorIndex) => {
console.log(colorIndex + ". " + color);
});
Example 3: javascript loop arrays
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
Example 4: javascript loop arrays
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
<label for="name" class="col-sm-3 control-label">Name: </label>
<div class="col-sm-6">
<input class="form-control" required="required" name="name" type="text" id="name">
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
Example 5: how to use for loops to work with array in javascript
for(let i = 0; i < myArray.length; i++){