I wanted to display a simple array's items on the console, using foreach. It dispalys all the items(it's OK), but it displays "cars : undefined" at the end. I dont want to display "cars : undefined", but only the 3 items of the array. How to do ?
var cars = [{
year: 2011,
type: "Volvo"
}, {
year: 1999,
type: "Volvo"
}, {
year: 2003,
type: "Volvo"
}];
console.log("1");
console.log("cars : " + cars.forEach(a => console.log(a)));
console.log("2");
forEach()returnsundefined. You're logging that value.