I need send the objects to api. But I need to change one value of the object in every step of the loop.
this.task = {
RowId: 0
};
var taskWithFid = [];
var fids = [1,2,3,4,5];
var taskTemp = this.task;
fids.map(function(fid){
taskTemp.RowId = fid;
taskWithFid.push(taskTemp);
}.bind(this));
I expect taskWithFid array like this:
[
{ RowId: 1 },
{ RowId: 2 },
{ RowId: 3 },
{ RowId: 4 },
{ RowId: 5 }
]
But I get this:
[
{ RowId: 5 },
{ RowId: 5 },
{ RowId: 5 },
{ RowId: 5 },
{ RowId: 5 }
]
Can you help me with that?
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<link rel="stylesheet" href="style.css">
<script data-semver="1.2.13" src="http://code.angularjs.org/1.2.13/angular.js" data-require="[email protected]"></script>
<script src="script.js"></script>
</head>
<body ng-controller="MainCtrl as item">
<h1>Hello Plunker!</h1
<div>{{item.taskWithFid}}</div>
</body>
</html>