如何更新本地存储阵列的特定键值? [英] How do I update specific key value of the local storage array?

查看:68
本文介绍了如何更新本地存储阵列的特定键值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像下面这样的本地存储阵列

I have a local storage array like below

pageItems  = {"stationID":"145","categoryID":"-1","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}

我需要将categoryID值更新为65

I need to update categoryID value to 65

pageItems  = {"stationID":"145","categoryID":"65","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}

推荐答案

您可以使用以下内容;

You can use following;

var pageItems  = '{"stationID":"145","categoryID":"-1","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}';

var json = JSON.parse(pageItems);

json.categoryID = 65;

pageItems_v2 = JSON.stringify(json);

这是一个有效的演示: 演示

Here is a working demo : Demo

这篇关于如何更新本地存储阵列的特定键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆