开发者

Detect [i] value

开发者 https://www.devze.com 2023-01-30 04:32 出处:网络
I am trying to make a condition where [i] is a value for data.length, the problem is that everything works okay when there are more than 1 value, but when theres only 1 value, the script doesnt work.

I am trying to make a condition where [i] is a value for data.length, the problem is that everything works okay when there are more than 1 value, but when theres only 1 value, the script doesnt work.

        out.href = data[i].href;
        out.innerHTML = data[i].alt;
        out.appendChild(document.createElement('br'));
    }
}

Explanation: When data.length is more than 1, the result will be object1.href, object2.href, etc. But when the returned query is only of 1 value, i want it to write just "object.href" without the [i] in it, because this works with yql and when yql returns only 1 o开发者_如何学JAVAbject, the object number is direct, doesnt have any value. Instead of object1.href, there will only be object.href but the script keeps placing the value in object[i].href thus failing when only 1 result is returned.

Is there any if...else method for this?


Check the count value which is returned with every YQL response.

if (o.query.count == "1") {
    data = [data];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号