在angularJS中合并两个数组

Jin*_*ina 4 javascript arrays angularjs

我有两个数组,我想将它们合并到一个数组中以将数据绑定到HTML表单,这就是我所做的:

控制器:

$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;
        });
}
Run Code Online (Sandbox Code Playgroud)

我想合并"finalOperationsList"数组和"listOperationsById"数组的内容,并使用"listfinal"将内容发送到我的表单

但是我在控制台中得到了这个:

$scope.listfinal :[{ content of finalOperationsList},null]
Run Code Online (Sandbox Code Playgroud)

那么请问我如何更正我的代码以获取来自"finalOperationsList"和"listOperationsById"数组合并的所有数据,感谢您的帮助

and*_*y83 6

考虑使用concat JavaScript方法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]
Run Code Online (Sandbox Code Playgroud)