【发布时间】:2020-06-24 13:22:35
【问题描述】:
如何制作这样的图案?我无法编写代码,因为我是新手。
这是我的代码
array = 1,2,3,4,5
const note = new notedModel ({
_id: array,
note: args[1],
});
如果您要求,也可以使用其他模块。
【问题讨论】:
标签: javascript node.js mongoose
如何制作这样的图案?我无法编写代码,因为我是新手。
这是我的代码
array = 1,2,3,4,5
const note = new notedModel ({
_id: array,
note: args[1],
});
如果您要求,也可以使用其他模块。
【问题讨论】:
标签: javascript node.js mongoose
希望对你有帮助
const array = [1,2,3,4,5];
const notes = array.map(element => new notedModel({
_id: element,
note: args[1], // or maybe args[element] if you need to select arg by array's element
}));
附:您可以在此处阅读答案以小心使用 id:How do you implement an auto-incrementing primary ID in MongoDB?
【讨论】:
希望对你有帮助
class NotedModel{
constructor(id, arg){
this._id = id
this._note = arg
}
}
var arr = [1, 2, 3, 4, 5]
var note = [];
for(i = 0; i < arr.length; i++){
note.push(new NotedModel(arr[i], i));
}
console.log(note);
【讨论】: