更改 json 数组 localstorage 的值
我想将数组 2 的“Used”值从 0 更改为 1 我正在将所述数组保存在本地存储中
0: {Referencia: "AV02", Descripcion: "TEXT", Precio: "30", Usado: 0}
1: {Referencia: "AV02", Descripcion: "TEXT", Precio: "30", Usado: 0}
2: {Referencia: "AV04", Descripcion: "TEXT", Precio: "0.35", Usado: 0}
3: {Referencia: "AV01", Descripcion: "TEXT", Precio: "45", Usado: 0}
I would like to change the Used value of for example array 2 from 0 to 1
I am saving said array in localstorage
0: {Referencia: "AV02", Descripcion: "TEXT", Precio: "30", Usado: 0}
1: {Referencia: "AV02", Descripcion: "TEXT", Precio: "30", Usado: 0}
2: {Referencia: "AV04", Descripcion: "TEXT", Precio: "0.35", Usado: 0}
3: {Referencia: "AV01", Descripcion: "TEXT", Precio: "45", Usado: 0}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您是在问当对象是数组的元素时如何更改对象属性的值。如果是这样:
在执行此操作之前,您必须从 localStorage 检索数据,并在完成后将其以相同键放回本地存储(根据需要使用 JSON 字符串化和解析步骤,本地存储仅存储字符串,对象和数组具有在存储之前转换为字符串)。
I'm guessing you are asking how to change the value of an object property when the object is an element of an array. If so:
You would have to retrieve the data from localStorage before doing this and put it back to local storage under the same key when you were done (with JSON stringifying and parsing steps as needed, local storage stores strings only, objects and arrays have to be converted to strings before storing).