1. 程式人生 > >JS for循環實現 My cats are called Bill, Jeff, Pete, Biggles, and Jasmin.

JS for循環實現 My cats are called Bill, Jeff, Pete, Biggles, and Jasmin.

length all lin nbsp 實現 blog call text style

var cats = [‘Bill‘, ‘Jeff‘, ‘Pete‘, ‘Biggles‘, ‘Jasmin‘];
var info = ‘My cats are called ‘;
for (var i = 0; i < cats.length; i++) {
  if (i === cats.length - 1) {
    info += ‘and ‘ + cats[i] + ‘.‘;
  } else {
    info += cats[i] + ‘, ‘;
  }

}
console.log(info)

JS for循環實現 My cats are called Bill, Jeff, Pete, Biggles, and Jasmin.