I have this solved, but I am looking to see if there is a better way to do this. Fiddle - https://jsfiddle.net/143h9wrq/ So what I do is check to see if there are 2+ Ids, then turn the string into an array, take the last array item and add 'and ', put it back together and display it.
I am looking to see if there is a better way to condense that if. I am using Angular in the project, not in the example. Basicly listArr would be $scope.listArr and issues is $user.issues.
JS:
var issuesId =[1,2,3,4]
var issues = "issue one, issue two, issue three, issue four";
if (issuesId.length >= 2) {
var str = issues.split(', ');
var addAnd = str.pop();
addAnd = 'and ' + addAnd;
str.push(addAnd);
var listArr = str.join(', ');
document.getElementById('text').innerHTML = listArr;
}
else {
var listArr = issues;
document.getElementById('text').innerHTML = listArr;
}
HTML:
<p>{{listArr}}</p>
,before theandwhen none is needed.angularjs- And that approach is nothing like an angularjs approachlistArron the scope.