我剛剛遇到了這個奇怪的問題,其中下面的代碼按預期返回數組中所有對象的 refno但是let records = await Expense.find({}).exec(); // records is an array of objects [{},{}] for (let obj of records) { // the obj has a refno property which i want to change obj.refno = 0 // this works as expected by changing refno property to 0 }console.log(records)下面這段代碼將屬性值更改為字符串不起作用 for (let obj of records) { obj.refno = "QM"+obj.refno }console.log(records) // IN this the refno. doesnt change我的要求是將 refno 更改為字符串//the object{ _id: 5efed2c813b03d331e4dc052, refno: 102, project: 'EV Battery Pack', invoiceno: 'dia', description: 'black frame', date: '2020-07-03',}所以將屬性更改為其他數字有效,但不是字符串,我無法理解這是如何發生的,或者我錯過了什么?無論如何我通過聲明另一個屬性并將字符串存儲在其中解決了這個問題,但我不知道為什么 int 不能更改為對象內的字符串有人可以解釋為什么會發生這種情況謝謝幫助編輯:費用模式var schema = new Schema({ refno: { type: Number, require: true }, project: { type: String, require: true }, projectid: { type: Number, require: true }, invoiceno: { type: String, require: true }, description: { type: String, require: true }, date: { type: String, require: true }, INR: { type: Number, require: true }, USD: { type: Number, require: true }, remarks: { type: String, require: true },});
nodejs objects 屬性只能更改為 int 而不是 string
慕娘9325324
2022-10-27 16:01:12