xxxxxxxxxx
// Global variable
var globalVariable = "someValue";
// Array of objects
var myArray = [
{ id: 1, name: "John" },
{ id: 2, name: "Jane" },
{ id: 3, name: "Alice" },
];
// Using the `find` method with a global variable
var result = myArray.find(function(obj) {
return obj.name === globalVariable;
});
console.log(result); // Outputs the matching object