Last active
May 18, 2020 19:25
-
-
Save juanbrusco/cbe077884ca8501ef100ede571027bda to your computer and use it in GitHub Desktop.
Find item into array by string input - Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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