I have an array like this:
"links": [{
"url": "http:...",
"title": "3"
}, {
"url": "http://facebook.com/pages/",
"title": "2"
},{
"url": "http://...",
"title": "2"
}],
I want to find out of the array has the word 'facebook' and if so to take the specific url with the word and use it. I tried this code but it doesn't work.
var arraylinks = mdata.links;
if (arraylinks[i].url === "facebook") {
for (var i = 0; i < arraylinks.length; i++) {
var klink = $("<a>").attr("href", arraylinks[i].url).attr('target', '_blank').addClass("icon-library");
}
}
I would appreciate your help. thank you
facebookis only part of the full url, you could test it with/facebook/i.test(arraylinks[i].url)or something similar to make sure it actually contains the word facebook