Javascript 如何将对象推入角度为6的对象数组中?

Javascript 如何将对象推入角度为6的对象数组中?,javascript,html,angular,angular2-forms,Javascript,Html,Angular,Angular2 Forms,我有一个像这样的空对象数组groupList:any={},现在我想把一个对象推入其中。我试图将名称和描述作为一个对象。它不是数组,数组表示为[],可能您需要 groupList:any = []; 然后呢, this.groupList.push({name:'you',description:'what is array'}); app.component.ts app.component.html 上一个值 是的,它不是一个数组,但我尝试使用角度形式将其推入其中,以获得以下结构:“gr

我有一个像这样的空对象数组
groupList:any={}
,现在我想把一个对象推入其中。我试图将名称和描述作为一个对象。

它不是数组,数组表示为[],可能您需要

groupList:any = [];
然后呢,

this.groupList.push({name:'you',description:'what is array'});
app.component.ts app.component.html
上一个值

是的,它不是一个数组,但我尝试使用角度形式将其推入其中,以获得以下结构:
“groupList”:{{{“name”:group1”,“description”:“descrption1”}
@OliverQueen您编写的JSON无效,您不能在另一个对象中包含这样的对象。一个对象由属性名称和值组成,因此您不能包含这样的“未命名”属性。您是否可能将其与字典混在一起?例如
“groupList”:{“group1”:“description1”,“group2”:description2“}
groupList
在这里不是数组,它只是一个普通的旧对象。我怀疑将其称为“对象数组”会引起一些混淆“.我想可以用一个例子来说明这一点-如果
组列表
中存储了多个对象,你能在问题中包括这应该是什么样子吗?请阅读-总结是,这不是一种理想的解决志愿者问题的方法,可能会对获得答案产生反作用。请不要把这个添加到你的问题中。嘿,奥利弗,你能标出答案吗?
declare var require: any;
import { Component } from '@angular/core';
import { OnInit } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
    groupList:any = [];
    arrayVal:any;
    currentVal : any;
  title = 'projectchart';
  public array = [{"id":1},{"id":3},{"id":5}];

 getPrev(){

     this.array.forEach((item, index) => {

  this.groupList.push(item.id);

});
console.log(this.groupList); 
 }


}
<button (click) ="getVal()">Previous Value</button>