【发布时间】:2020-01-13 02:56:18
【问题描述】:
我正在 Ionic Angular 中处理一些数组,并且我有以下代码:
this.items = [];
this.places = [{"first_name":"joe","last_name":"Jobs","description":"engineer"},
{"first_name":"mary","last_name":"trump","description":"doctor"}];
我需要得到这个:
this.items =[{"first_name":"joe","description":"engineer"},{"first_name":"mary","description":"doctor"}];
我有这个
this.places.forEach((item) => {
this.items.push('{"name:"'+
item.first_name+',"description":'+item.description+'}');
}
我收到此错误消息:
无法读取未定义的属性“push”
有人可以指导我正确的方式吗?
【问题讨论】:
标签: javascript arrays loops object