js 数组合并

在数组d前面增加

d.unshift({id:"0",classname:'全部',htmlurl:'ypkj'})


在数组d后面增加

d.push({id:"0",classname:'全部',htmlurl:'ypkj'})


数组合并

var c = Object.assign({
        key: this.data.accesskey,
        openid: this.user.openid
      }, data);


数组字段转换

 str.forEach(function(val,index,arr){
                var stria = val.split('|');
                var strib = {'title':stria[1],'picurl':_this.data.imgurl + stria[0]};
                arrs[index] = strib;
            })



字符串转化为数组

      var a = "1|2||23|22||32|33||32|3"
      photo:function(a){
            var _this = this;
            var p = a;
            var str = p.split('||');
            var x,arrs={}
            str.forEach(function(val,index,arr){
                var stria = val.split('|');
                var strib = {'title':stria[1],'picurl':_this.data.imgurl + stria[0]};
                arrs[index] = strib;
            })
           return arrs;
       }


小程序数组push必须循环

 // 通过 tid 获取 列表信息
       let _t = this;
          app.api('POST', tid, {ajax:1,page:this.data.page,isshow:1}, (res) => {
            let data = res.data.data
            if(data.length>=1){
              if(add==1){
                let list = _t.data.listl1;
                data.forEach(function(val,index,arr){
                  list.push(val);
                })
                data = list;
              }
              _t.setData({listl1:data,nolist:false,moreloading:true})
            }
            else{
              _t.setData({moretxt:'已经到底',moreloading:true});
            }
          })


发布时间:2021-05-26 05:03:31

觉得有用请点个赞吧!
128 0