Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Last active May 18, 2020 19:25
Show Gist options
  • Save juanbrusco/cbe077884ca8501ef100ede571027bda to your computer and use it in GitHub Desktop.
Save juanbrusco/cbe077884ca8501ef100ede571027bda to your computer and use it in GitHub Desktop.
Find item into array by string input - Javascript
var heroes = [
{name: “Batman”, franchise: “DC”},
{name: “Ironman”, franchise: “Marvel”},
{name: “Thor”, franchise: “Marvel”},
{name: “Superman”, franchise: “DC”}
];
//this text should come from input
var query = "marvel";
let results = heroes.filter(function (el) {
return el.toLowerCase().includes(query.toLowerCase());
});
//filter by prop
const results = heroes.find(x => x.name === "Superman");
console.log(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment