数组新增,修改json数据

1.向数组中添加json数据

var arr=[];
var json = {"name":"apple","color":"red"}
arr.push(json)
console.log(arr)

 

返回结果:

 

2.新增 json 键值对

var fruit =[{"name":"banana"}];  
fruit[0].color='yellow'
console.log(fruit)

 

返回结果:

 

posted @ 2018-10-17 10:51  前端[色色]  阅读(3150)  评论(0编辑  收藏  举报