search input at array javascript
var people = [
{
name: "John Smith",
url: "http://example.com/johnsmith"
},
{
name: "John Johnson",
url: "http://example.com/johnjohnson"
},
{
name: "Bob Thompson",
url: "http://example.com/bobthompson"
},
{
name: "Smith Sanchez",
url: "http://example.com/smithsanchez"
},
{
name: "Bob Sanchez",
url: "http://example.com/bobsanchez"
}
];
$("#search-input").on("keyup", function(){
var searchFor = $("#search-input").val().toLowerCase();
var results = [];
for(var i=0;i<people.length;i++){
if(people[i].name.toLowerCase().indexOf(searchFor) > -1)
results.push("<a href='"+people[i].url+"' target='_blank'>"+people[i].name+"</a>")
}
if(results.length == 0)
$("#search-results").html("No Results Found");
else
$("#search-results").html(results.join("<br>"));
});
Also in JavaScript:
- jquery wait for element to exist
- enzyme hasclass example
- binary to ascii javascript
- Javascript remove empty elements from array
- express get query params from url
- javascript unique array of objects by property
- js number add zero before
- javascript percent to int
- how to remove last index of array in javascript
- how to get session value using javascript
- for in loop javascript
- javascript get width of image
- url_for javascipt
- queryselector javascript varias clases
- javascript keep scroll visible
- angular add bootstrap
- nodejs print
- eval in js
- js num to string with leading 0
- react html symbol code
- drupal 8 check if current page is node
- pub js npm
- express file upload mv
- react native componentwillmount vs componentdidmount