我有一对佛瑞斯:
- 《Shiloh Match Jolie》
- 《扎哈拉·马利小说》,
- 《Pax Dix Bat》,
- "Maddox Chivan Jcalie"
我想要得到所有的最后一个角色:
AngularJs中的"朱莉"、"小说"、"蝙蝠"、"Jcalie".
你能帮帮我吗?
谢谢大家!
我有一对佛瑞斯:
我想要得到所有的最后一个角色:
AngularJs中的"朱莉"、"小说"、"蝙蝠"、"Jcalie".
你能帮帮我吗?
谢谢大家!
我添加了一个额外的函数,它返回phrase
的最后一个单词
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
$scope.phrases = ["Shiloh Match Jolie", "Zahara Marley Novel", "Pax Dix Bat", "Maddox Chivan Jcalie"];
// Returns the last word of a phrase
$scope.getLastWord = function (phrase) {
var words = phrase.trim().split(' ');
return words[words.length - 1];
};
// Returns the last character of a phrase
$scope.getLastCharacter = function (phrase) {
// Assuming the phrase is not empty
return phrase.trim().slice(-1);
};
});
<div ng-app="myApp" ng-controller="myCtrl">
<ul>
<li ng-repeat="phrase in phrases">
Last Word in the Pharse : {{ getLastWord(phrase) }}
Last Character in the Last Word of the Pharse: {{ getLastCharacter(phrase) }},
</li>
</ul>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>