显示数组如下所示

时间:2017-09-27 11:00:39

标签: angularjs

var $scope.data = [
{
   id: 1,
   name: "Akash"
},
{
   id: 2,
   name: "Vipul"
},
{
   id: 3,
   name: "Mahesh"
}];
var character = [];       
_.filter($scope.data, function (item) {
   character.push(item.id);
});
console.log("Character::", character);

输出::字符:: [" 1"," 2"," 3"]

我希望输出如下:

你的角色是1,2和3。

2 个答案:

答案 0 :(得分:1)

请查看以下

char [] data = { 'C', 'c', 'b', 'B', 'A' };
string joinString = string.Join( ", ", data );

string result = string.Format( "your character is {0}", joinString.Insert( joinString.LastIndexOf(",")+1, " and") );

答案 1 :(得分:0)



var arr = [ "C", "c", "b", "B", "A" ];
var text ="";
arr.forEach(function(val,index){
  if(index <= arr.length-2){
    text = text +  val +","
  }else{
    text = text +" and " +val
  }

  
})
console.log("Your characters are",text)
&#13;
&#13;
&#13;