js数组用逗号形式隔开

遍历数组:

let fh = ',';
let tagArr = [
{id:1,tageName:"张三",age:10},
{id:2,tageName:"李斯",age:20},
{id:3,tageName:"李丽",age:30}
]
let strTag = tagArr.map(function(obj,index){
                      if(obj!=null){
                        if(obj.tagName!=null){
                          return obj.tagName;
                        }else{
                          fh = ''
                        }
                      }else{
                        fh = ''
                      }
                  }).join(fh);
console.log(strTage,'>>>>');//结果:strTage = 张三,李斯,李丽

 

posted on 2020-08-14 09:21  婧星  阅读(10219)  评论(0编辑  收藏  举报

导航