I am working in angularjs project,
var res = ["Art","Logic","Science"];
$scope.output = res;
Result is displayed as
Art,Logic,Science
I need the result as -
Art, Logic, Science
Have to add space between each string array value.
You can use the join()
method to achieve this.
var myapp = angular.module('myapp', []); myapp.controller('SpaceCntrl', function($scope) { var result = ["Art", "Logic", "Science"]; $scope.res = result.join(', '); });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myapp"> <div ng-controller="SpaceCntrl"> <span ng-bind="res"></span> </div> </div>
Joining the array will do it :)
var res = ["Art","Logic","Science"];
$scope.output = res.join(', ');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.