For example there are two array of object and you want to print out each element, it is bad if you use two forEach method on each array:
var people1 = [
{
name: 'Mikko'
},
{
name: 'Radu'
}
]; var people2 = [
{
name: 'Jarno'
},
{
name: 'Jussi'
}
]; people1.forEach( (person) => {
console.log(person.name);
}); people2.forEach( (person) => {
console.log(person.name);
});
If use concat() can solve the problem:
var people1 = [
{
name: 'Mikko'
},
{
name: 'Radu'
}
]; var people2 = [
{
name: 'Jarno'
},
{
name: 'Jussi'
}
]; people1
.concat(people2)
.forEach( (person) => {
console.log(person.name);
});