答案 0 :(得分:0)
结束循环数据本身。
// new array for repopulating
var new_array = new Array();
// new key order
var new_order = ['Year', 'RENEWABLE POWER PLANTS', 'NUCLEAR POWER PLANTS', 'FOSSIL POWER PLANTS W/CCS', 'BIOFUELS', 'SYNTHETIC FUELS', 'VEHICLES', 'BUILDING TECHNOLOGIES', 'OTHER EFFICIENCY', 'OTHER', 'NATURAL GAS', 'COAL', 'PETROLEUM PRODUCTS', 'FOSSIL POWER PLANTS'];
// for each row in 'data'
for (i = 0; i < data.length; i += 1) {
var new_data = {};
// go through the 'new order' array
for (z = 0; z < new_order.length; z += 1) {
// re-order the keys in a new array
new_data[new_order[z]] = data[i][new_order[z]];
}
// add the row to a new array
new_array.push(new_data);
}
// replace data with the new array
data = new_array;