updateSerialNumbers
This commit is contained in:
parent
7a4449ccfb
commit
d6743ed600
21
update-serial-numbers.js
Normal file
21
update-serial-numbers.js
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
import fs from 'fs/promises';
|
||||
|
||||
async function updateSerialNumbers() {
|
||||
try {
|
||||
const filePath = './data.json';
|
||||
const data = await fs.readFile(filePath, 'utf-8');
|
||||
const records = JSON.parse(data);
|
||||
|
||||
for (let i = 0; i < records.length; i++) {
|
||||
records[i]['序号'] = (i + 1).toString();
|
||||
}
|
||||
|
||||
await fs.writeFile(filePath, JSON.stringify(records, null, 4), 'utf-8');
|
||||
console.log('data.json 文件中的序号字段已更新,并按顺序重新编号。');
|
||||
} catch (error) {
|
||||
console.error('更新序号时发生错误:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
updateSerialNumbers();
|
||||
Loading…
Reference in New Issue
Block a user