let resultList = [{"name":"a1"},{"name":"b1"}]
resultList.forEach(tem => {
tem.age = 1;
})
循环向数组resultlist中添加age属性
let resultList = [{"name":"a1","shapes":[{"age":12,"sex":"female"}]},{"name":"b1","shapes":[{"age":10,"sex":"male"}]}]
resultList.forEach(item => {
item.shapes.forEach(tem => {
tem.class = "1";
})
})
向数组中的子属性添加属性
var jsonStr = JSON.stringify(resultList);//将JSON对象转化为JSON字符
或者var jsonStr=resultList.toJSONString(); //将JSON对象转化为JSON字符(需要json包的支持,提示错误可以检查json包版本是否有点低)