如何在json对象中替换嵌套数组

时间:2017-09-24 21:10:16

标签: javascript json angular

我在我的项目中使用了角度2,这是我的json对象:

{"departure":"ville","stations":[{"station":"r"}]}

我想要的是用{{“station”:“Rabat”}替换[{“station”:“r”}],预期的对象是:

{"departure":"ville","stations":[{"station":"Rabat"}]}

任何帮助吗??

1 个答案:

答案 0 :(得分:0)

你可以做到

let obj = {"departure":"ville","stations":[{"station":"r"},{"station":"j"},{"station":"i"}]};

console.log(obj);

obj.stations = [{"station":"toto"},{"station":"titi"},{"station":"momo"}];

console.log(obj);