function search(nameKey, myArray){ for (var i=0; i < myArray.length; i++) { if (myArray[i].name === nameKey) { return myArray[i]; } } } var array = [ { name:"string 1", value:"this", other: "that" }, { name:"string 2", value:"this", other: "that" } ]; var resultObject = search("string 1", array);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter