javascript - Determine object index of a specific string -
im looking iterate through next object , determine index item-2 (or other string) belongs too. in case expect index [0] , case of item-2 [1]
the string im looking determine index for, exist first object index - in below illustration item-1 , item-2
var products = [ ["item-1", "image1.png", "image2.png", "image3.png" ], ["item-2", "image1.png", "image2.png" ] ]; any suggestions on how go this? thinking loop , doing indexof string check - not exclusively sure how search first index or similar.
something this?
function findindex(inputarray, searchitem) { (var = 0; < inputarray.length; i++) { if (inputarray[i][0] == searchitem) homecoming i; } homecoming -1; // not found } javascript arrays indexof
No comments:
Post a Comment