Trouble using indexOf on a complex array [duplicate]
问题 Possible Duplicate: indexOf method in an object array? I have a javascript array which follows this format: var arrayName = [ {id: "a", gender: "man", item: "stuff"}, {id: "b", gender: "woman", item: "stuff"}, {id: "c", gender: "man", item: "stuff"}, {id: "d", gender: "man", item: "stuff"} ]; Is there a way that I can use array.indexOf to find an index in the array, when for example I know the "id" variable. For example I tried; var position = arrayName.indexOf("b"); arrayName[position]