Q:

How to add auto-increment number when pushing item in array using angular?

I am trying to push the value into the array and then showing in the view. All is working fine but i want to add auto-increment number with the item. I have following array in data.json file
[   
    {"id":1,"name":"John","gender":"Male"},
    {"id":2,"name":"Smith","gender":"Male"},
    {"id":3,"name":"Linda","gender":"Female"},
    {"id":4,"name":"Jerry","gender":"Female"}
]

In the user.service file 
private JsonDirectory: string = "assets/data.json"
constructor(private _httpReference: Http){}
getUsers(){
    return this._httpReference.get(this.JsonDirectory)
        .map((responseReference:Response) => responseReference.json());
}

In the user.component i am pushing the input value into the array on pressEnter event, since i have only one input value so i have pushed but there is also id and it should be auto-incremented. Following are code which i am trying
UserArray = [];
constructor(private userService: UserService, private _location: Location){}
show_value: string = '';
    OnPressEnter(show_value: string){ 
        var inputValue = show_value;
        this.show_value = show_value;
        this.UserArray.push({"id":5,"name":inputValue }); 
    }

You can see id is static i want to make it dynamic.
<ul>
<li *ngFor="let userCourse of UserArray" (click)="onSelect(userCourse.name)">
<span>{{userCourse.id}}</span> | <a style="cursor:pointer;">{{userCourse.name}} </a>
</li>
</ul>

A:

you can use like this
  OnPressEnter(show_value: string){ 
            var inputValue = show_value;
            this.show_value = show_value;
            this.UserArray.push({"id":this.UserArray.length+1,"name":inputValue }); 
        }

