0

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.

3 Answers 3

1

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>

Sign up to request clarification or add additional context in comments.

Comments

0

This is how I usually do it:

$scope.output = res.join(', ');

Using Array.propotype.join()

Comments

0

Joining the array will do it :)

var res = ["Art","Logic","Science"];
$scope.output = res.join(', ');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.