I am using the Instagram API onto my website and need to grab only the first few words of the description of the first 8 pictures.
My problem is that if I try to take more than 11 words per picture, the page stops loading.
Here's my code:
success: function (data) {
console.log(data);
data.data.forEach(function (pic) {
var height = pic.images.standard_resolution.height;
var width = pic.images.standard_resolution.width;
if (width == height && pic.type != "video") {
$("#img" + i).append("<img class='img-fluid' alt='placeholder' src=\"" + pic.images.standard_resolution.url + "\" > ");
var text = pic.caption.text;
var s = ""
var words = 0;
var j = 0;
while (words < 11 || j < text.length) {
if (text[j] == ' ') {
words++;
}
s += text[j];
j++;
}
$("#img" + i).append("<div class='mask flex-center waves-effect waves-light rgba-black-light'><p id='txt" + i + "' class='white-text'>" + s + "</p></div>");
i++;
}
});
}
I don't really know what I am doing wrong and what could be so terrible about 8 more words (I only fetch 8 pictures).
Thank you in advance for looking at my problem.