Push Item From One Array Into another Array in Angular
16,489
Solution 1
$scope.tasks = [
{title: "Do the dishes"},
{title: "Walk the dog"},
];
$scope.tasksDone = [];
$scope.addToTasksDone = function(index) {// IM FAILNG HERE};
$scope.tasksDone.push($scope.tasks[index]);
}
Solution 2
$scope.tasks.push(yourObject)
this question was aked before here
Solution 3
$scope.tasks = [
{ title: "Do the dishes" },
{ title: "Walk the dog" }
];
$scope.tasksDone = [];
for(var i in $scope.tasks){
$scope.tasksDone.push($scope.tasks[i]);
}
Author by
Julian Be
Updated on June 23, 2022Comments
-
Julian Be almost 2 years
I am programming an app with AngularJS and wanted to know how to push an item from one array into another array.Here is sample code:
$scope.tasks = [ {title: "Do the dishes"}, {title: "Walk the dog"}, ]; $scope.addToTasksDone = function() {// IM FAILNG HERE}; $scope.tasksDone = [];
How can I push the item with value "Do the dishes" to the tasksDone array?