AngularJs split string


AngularJs split string – There are many ways to split string . Here in this tutorial we are going to explain how you can use split() method to split the string in AngularJs. You can use our online demo try and edit the code online.


AngularJs split String to Array | Example

You can use split() method to split string into array. Here is full example –

AngularJs split String to Array | Comma Separated string Example:

<!DOCTYPE html>
<html lang="en">
<head>
 <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
 <script>
var myApp = angular.module("myApp", []);
 myApp.controller("myController", function($scope) {
 $scope.exampleString = "Mango, Banana, Grapes";
});
</script>
</head>
<body>  
<div ng-app="myApp">  
<div ng-controller="myController">  
String[0] = {{exampleString.split(',')[0]}}<br>
String[1] = {{exampleString.split(',')[1]}}<br>
String[2] = {{exampleString.split(',')[2]}}<br>

</div> 
</div>
</body>  
</html>  

Try it »

In the above example we have created a simple example to split the string in AngularJs.

If you run the above example it will produce the output something like this –

AngularJs split String to Array | Example


Advertisements

Add Comment

📖 Read More