如何在javascript中更新和删除对象值
Posted
技术标签:
【中文标题】如何在javascript中更新和删除对象值【英文标题】:How to update and delete object Value in javascript 【发布时间】:2016-03-05 02:42:58 【问题描述】:var key = "kay_1": "sample_1":"spmedata", "sample_2":"spmedata", , “凯_2”: "sample_1":"spmedata", "sample_2":"spmedata",
现在我的问题是如何更新和删除“kay_2”->“sample_1”键?
【问题讨论】:
使用点或括号表示法更新值:key['kay_2']['sample_1'] = 'new value'
。要删除使用delete key['kay_2']['sample_1']
。
谷歌是你的朋友
请看一下:developer.mozilla.org/en-US/docs/Web/javascript/Guide/…
需要一个完整的教程来通过 Native Javascript 操作 JSON 数据。
【参考方案1】:
var key="kay_1":
"sample_1":"spmedata",
"sample_2":"spmedata",
,
"kay_2":
"sample_1":"spmedata",
"sample_2":"spmedata",
// To update the value
key['kay_2']['sample_1'] = 'new value';
// To delete the key
delete key['kay_2']['sample_1']
【讨论】:
1:对象纬度:对象纬度:37.579412513438385 lng:-99.4976806640625 proto:对象 proto:对象 2:对象纬度:对象纬度:37.996162679728116 lng: -90.7745361328125 proto: Object proto: Object proto: Object 如何动态更新对象'2' latlng?代码会检查它是对象 1 还是对象 2?我有整数值,我已经检查过了,但它成为整数检查的对象?【参考方案2】:两种方式都可以更新
key.kay_2.sample_1 = "changed value";
key['kay_2']['sample_1'] = "changed value";
for delete is the same
delete key.kay_2.sample_1;
delete key['kay_2']['sample_1'];
【讨论】:
【参考方案3】:要修改值试试,
key.kay_2.sample_1 = "changed value";
删除,
delete key.kay_2.sample_1
【讨论】:
以上是关于如何在javascript中更新和删除对象值的主要内容,如果未能解决你的问题,请参考以下文章