With JavaScript, try to run the following code to check whether an array includes an object or not. Here, “true” will be returned to finding the specific object in the array −
Example
<!DOCTYPE html> <html> <body> <script> var book = [ { Name: 'Java', ID: '001' }, { Name: 'Ruby', ID: '002' }]; var result = false; for(var i = 0; i < book.length; i++) { if (book[i].Name == 'Ruby') { result = true; document.write(result.toString()); break; } } </script> </body> </html>
Output
true