javascript - concatenation of two arrays -
i have array:
$scope.array2 = ["3","4","5"]; $scope.array = [["1"],["2"],["3"]]; $scope.array[0].concat(array2); expected output:
$scope.array = [["1","3","4","5"],["2"],["3"]]; but array unchanged after concat. how can solve problem?
to desired result, you'd have this:
$scope.array2 = ["3","4","5"]; $scope.array = [["1"],["2"],["3"]]; $scope.array[0] = $scope.array[0].concat($scope.array2); array.prototype.concat returns result, instead of modifying it's subject.
you'll have save result of contact $scope.array[0].
also, have @ @phil's answer, using push, returns desired result, without having assign result separately.
Comments
Post a Comment