我声明一个空数组,然后使用for循环填充数组,如下所示:
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'Spetember', 'October', 'November', 'December'];
var monthGroups = [];
console.log(monthGroups)
for (var x = 0; x < array.length; x++) {
var value = array[x][instance.sortColumn.replace('set', instance.currentSet)];
for (var y = 0; y < months.length; y++) {
monthGroups[y] = monthGroups[y] ? monthGroups[y] : [];
if (value.indexOf(months[y]) > -1) monthGroups[y].push(array[x]);
}
}
有人可以解释为什么console.log返回填充的数组,而不是预期的空数组吗?