适用于小程序wxs和js
- index 本条数据索引
- ad 广告数组
- field 所要返回的广告字段
const isDisplayAd = function(index, ad, field = '') {
var perShow = 4 // 每隔n个显示广告
var adLength = ad.length
if (adLength > 0){
if ((index+1)%perShow === 0) {
var idx = (index+1)/perShow
return ad[parseInt((idx+adLength-1) % adLength)][field]
} else {
return -1
}
} else {
return -1
}
}