I have two arrays,I want to merge them into one array to bind the Data to the HTML form,this is what I did:
Controller:
$scope.modifierOuCreerArticle = function() {
var index = this.row.rowIndex;
$http.get("URL1")
.success(function(datagetArticle) {
$scope.finalOperationsList = datagetArticle.listElementGamme;
var v = $scope.finalOperationsList[$scope.finalOperationsList.length-1].operationId;
$scope.listOperationsById(v);
$scope.listfinal=$scope.finalOperationsList.concat($scope.listOperationsById);
$scope.finalOperationsList = $scope.listfinal;
});
$scope.listOperationsById = function(id) {
$http.get(URL2)
.success(function(data) {
$scope.listOperationsById = data;
});
}
I want to merge the content of "finalOperationsList" array and "listOperationsById" array and send the content to my form with the "listfinal"
but I get this in console:
$scope.listfinal :[{ content of finalOperationsList},null]
so please how can I correct my code to get the all data coming from the merge of "finalOperationsList" and "listOperationsById" arrays thanks for help
Consider using the concat JavaScript method https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
var alpha = ['a', 'b', 'c'],
numeric = [1, 2, 3];
var alphaNumeric = alpha.concat(numeric);
console.log(alphaNumeric); // Result: ['a', 'b', 'c', 1, 2, 3]
Use conact function
var a = ["1", "2", "3", "4"];
var b = ["5", "6", "7", "8"];
var c = a.concat(b);
OR
angular.extend(c, a, b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With