js 每两个图片插入一个广告怎么做?
要求每两张图片后插入一个广告,请问这怎么做,有偿,微信 jinnchen94
回答:
var arr = [1,2,3,4,5,6]for(let i = 2; i < arr.length; i+=2){
arr.splice(i++, 0, '') // 这里空字符串换成你的广告
}
arr // [1, 2, "", 3, 4, "", 5, 6]
回答:
setAdCustomZwy(items, pageNum) { if (!不符合条件) {
return items;
}
let start;
let space = this.config.space - 1;
if (pageNum == 1) {
start = this.config.firstAd - 1
} else {
start = this.isStart;
}
while (items.length > start) {
items.splice(start, 0, {
type: 'adCustom',
title: 'adCustom999',
videoId: 0
})
start = space + start + 1;
}
this.isStart = start - items.length;
return items;
},
回答:
var arr = [...Array(10).keys()];//生成0-9//[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
var obj = 'ad';//要添加的数据
arr.reduce((acc,cur,idx)=>(acc.push(cur),idx%2 && acc.push(obj),acc),[]);
//[0, 1, "ad", 2, 3, "ad", 4, 5, "ad", 6, 7, "ad", 8, 9, "ad"]
以上是 js 每两个图片插入一个广告怎么做? 的全部内容, 来源链接: utcz.com/p/935672.html