js如何删除json里的值
思路
第一种方法:通过把json中需要的值取出来,重新生成json对象,这种方法比较笨
第二种方法:通过delete 删除属性,这种方法比较常用,在第三方js库中经常能看到,推荐
举例
1
2
3
4
5
6
|
<script> var s = [{ "name" : "tank" , "total" : "100" },{ "name" : "zhang" , "total" : "23" },{ "name" : "hao" , "total" : "325" }]; for ( var k=0;k<s.length;k++){ delete s[k][ "name" ]; } </script> |
采纳率:72% 擅长: 暂未定制
其他回答
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
<!DOCTYPE HTML> < html > < head > < title >yugi</ title > < meta charset = UTF -8 /> < style type = "text/css" > </ style > < script type = "text/javascript" > var s = [ { "name" : "tank", "total" : "100" }, { "name" : "zhang", "total" : "23" }, { "name" : "hao", "total" : "325" } ]; for ( var i = 0; i < s.length; i++) { delete s[i].name; } console.log(s); </ script > </ head > < body > </ body > </ html > |