Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Find Object by id in an Array of Objects</title> </head> <body> <script> // Sample array var myArray = [ {"id": 1, "name": "Alice"}, {"id": 2, "name": "Peter"}, {"id": 3, "name": "Harry"} ]; // Get the Array item which matchs the id "2" var result = myArray.find(item => item.id === 2); document.write(result.name); // Prints: Peter </script> </body> </html>