javascript 如何使用jquery清除json对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15064969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to clear json object using jquery
提问by Francis Stalin
var json=[];
json.push({"id":"1","name":"abc"});
json.push({"id":"2","name":"xyz"});
after push my json like this
像这样推送我的 json 之后
json=[{"id":"1","name":"abc"},{"id":"2","name":"xyz"}];
Here i want to clear all the json
data
在这里我想清除所有json
数据
like this json=[]
像这样 json=[]
Is it possible in jquery
or javascript
?
有可能在jquery
或javascript
吗?
回答by PSR
reset to empty array
重置为空数组
json= [];
I think this solve your problem
我认为这可以解决您的问题
回答by Manuel
The easy answer is:
简单的答案是:
json.length = 0;
this will also free any memory associated with the object.
这也将释放与该对象关联的任何内存。
You could also delete the object with the delete
command:
您还可以使用以下delete
命令删除对象:
delete json;
回答by Van Coding
Try it with the following:
请尝试以下操作:
json.splice(0,json.length);