我试图搜索包含在对象数组中的字符串.
image_array = [ {image: '/assets/monkey-face.jpg', link_url: '/animal/showit?animal=Monkey'}, {image: '/assets/tiger-face.jpg', link_url: '/animal/showit?animal=Tiger'} ]
在url参数showit或图像中找不到字符串'monkey'或'tiger'.
image_array.IndexOf jQuery.inArray
如果我尝试遍历数组/对象并搜索我得到的字符串:
"Object #
我哪里错了 - 为什么当对象中包含字符串时它返回-1?
试试这个:
for(var i = 0; i < image_array.length; i++){ if(image_array[i].link_url.indexof("Monkey") != -1){ // Item found } }