Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

angular push in array of objects

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  
  myObjArray = [
    {id: 1, name: "Hardik" },
    {id: 2, name: "Vimal" },
    {id: 3, name: "Paresh" }
  ];
  
  addNew(){
    this.myObjArray.unshift({id: 4, name: "Vimal"});
    console.log(this.myObjArray);
  }
}
Source by www.itsolutionstuff.com #
 
PREVIOUS NEXT
Tagged: #angular #push #array #objects
ADD COMMENT
Topic
Name
1+3 =