我使用的是低数据库https://github.com/typicode/lowdb。我有一个小型数据库,如下所示
{
"orders": [
{
"id": "0",
"kit": "not a real order"
},
{
"id": "1",
"kit": "kit_1"
}
],
"total orders": 21,
"216862330724548608": 1
}是否可以将"kit": "x"更改为"kit": "y"
X和y是用户输入,所以我不能只使用replace,因为我不知道它等于什么。
我确实尝试过使用某种替换,但它不起作用
发布于 2019-06-12 03:56:30
let = updateOrders = (items, id, newValue) => {
const {orders} = items;
orders.map((item) => {
item.kit = newValue;
//if you need id check uncomment below code and add id in arguments and pass id
// if (item.id === id) {
// item.kit = newValue;
// }
})
console.log(orders);
};
updateOrders(orders, 'updated');希望这能有所帮助。
https://stackoverflow.com/questions/56547500
复制相似问题