Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>JavaScript live search</h1>
<input autocomplete="off" type="search" id="search" placeholder="Search for a country or name!" />

<ul id="results"></ul>
              
            
!

CSS

              
                body {
  display: flex;
  min-height: 100vh;
  align-items: center;
    font-family: Roboto,"Helvetica Neue",Arial,sans-serif;
  flex-direction: column;
}
input {
  width: 250px;
  text-align: center;
}
ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
}
              
            
!

JS

              
                const data = [
  { name: "Ryan", country: "Saint Lucia" },
  { name: "Malcolm", country: "Portugal" },
  { name: "Dalton", country: "Brazil" },
  { name: "Imelda", country: "Chad" },
  { name: "Aubrey", country: "Bulgaria" },
  { name: "Brittany", country: "Guatemala" },
  { name: "Jelani", country: "El Salvador" },
  { name: "Merritt", country: "Honduras" },
  { name: "Shannon", country: "Zambia" },
  { name: "Leroy", country: "Cyprus" },
  { name: "Abel", country: "Greenland" },
  { name: "Demetria", country: "Trinidad and Tobago" },
  { name: "Kelly", country: "Jordan" },
  { name: "Beverly", country: "Korea, South" },
  { name: "Yasir", country: "Brunei" },
  { name: "Addison", country: "New Caledonia" },
  { name: "Coby", country: "Guatemala" },
  { name: "Rowan", country: "Lesotho" },
  { name: "Kasimir", country: "United Arab Emirates" },
  { name: "Karly", country: "Bermuda" },
  { name: "Damian", country: "Trinidad and Tobago" },
  { name: "Bevis", country: "New Caledonia" },
  { name: "Colin", country: "Chile" },
  { name: "Kenneth", country: "Indonesia" },
  { name: "Chester", country: "Falkland Islands" },
  { name: "Elvis", country: "Christmas Island" },
  { name: "Diana", country: "El Salvador" },
  { name: "Maya", country: "Tokelau" },
  { name: "Katell", country: "Svalbard and Jan Mayen Islands" },
  { name: "Ori", country: "Japan" },
  { name: "Ria", country: "Sweden" },
  { name: "Seth", country: "Indonesia" },
  { name: "Rooney", country: "Iran" },
  { name: "Ronan", country: "Fiji" },
  { name: "Herrod", country: "American Samoa" },
  { name: "Chanda", country: "Niger" },
  { name: "Imani", country: "Croatia" },
  { name: "Zachery", country: "Ghana" },
  { name: "Suki", country: "Austria" },
  { name: "Rachel", country: "Liechtenstein" },
  { name: "Leslie", country: "Korea, North" },
  { name: "Chastity", country: "Sudan" },
  { name: "Sydney", country: "Malaysia" },
  { name: "Ahmed", country: "Saint Pierre and Miquelon" },
  { name: "Quail", country: "Puerto Rico" },
  { name: "Ima", country: "Paraguay" },
  { name: "Harrison", country: "Armenia" },
  { name: "Meredith", country: "Venezuela" },
  { name: "Orson", country: "Ecuador" },
  { name: "Rudyard", country: "Burundi" },
  { name: "Lillian", country: "Somalia" },
  { name: "Jessica", country: "Cyprus" },
  { name: "Beck", country: "Mozambique" },
  { name: "Lev", country: "Sudan" },
  { name: "Edan", country: "Latvia" },
  { name: "Naomi", country: "Rwanda" },
  { name: "Quentin", country: "Fiji" },
  { name: "Kelly", country: "Viet Nam" },
  { name: "Delilah", country: "Madagascar" },
  { name: "Porter", country: "Benin" },
  { name: "Slade", country: "China" },
  { name: "Yuli", country: "Grenada" },
  { name: "Larissa", country: "Samoa" },
  { name: "Hermione", country: "French Polynesia" },
  { name: "Jeremy", country: "Botswana" },
  { name: "Garrison", country: "Argentina" },
  { name: "Alexis", country: "Switzerland" },
  { name: "Riley", country: "Malawi" },
  { name: "Jermaine", country: "Bulgaria" },
  { name: "Wylie", country: "Central African Republic" },
  { name: "Jenette", country: "Oman" },
  { name: "Angelica", country: "Laos" },
  { name: "Noel", country: "Guatemala" },
  { name: "Melyssa", country: "Peru" },
  { name: "Raven", country: "Anguilla" },
  { name: "Nissim", country: "Chad" },
  { name: "Timothy", country: "Macedonia" },
  { name: "Leroy", country: "Eritrea" },
  { name: "Veda", country: "Lesotho" },
  { name: "Neil", country: "Guam" },
  { name: "Sasha", country: "Samoa" },
  { name: "Karly", country: "China" },
  { name: "Kasimir", country: "Jamaica" },
  { name: "Zachery", country: "Sudan" },
  { name: "Zia", country: "Iceland" },
  { name: "Cassandra", country: "Singapore" },
  { name: "Zeus", country: "Serbia" },
  { name: "Rachel", country: "Armenia" },
  { name: "Drake", country: "India" },
  { name: "Janna", country: "Peru" },
  { name: "Daphne", country: "Mayotte" },
  { name: "Ahmed", country: "Moldova" },
  { name: "Yael", country: "Sao Tome and Principe" },
  { name: "Charity", country: "Estonia" },
  { name: "Chase", country: "Ethiopia" },
  { name: "Jessamine", country: "Curaçao" },
  { name: "Edward", country: "Morocco" },
  { name: "Jack", country: "Kuwait" },
  { name: "Gregory", country: "Zimbabwe" },
  { name: "Hiroko", country: "Kenya" }
];

const search = document.getElementById("search");
const results = document.getElementById("results");
let search_term = "";

const showList = () => {
  results.innerHTML = "";
  data
    .filter((item) => {
      return (
        item.country.toLowerCase().includes(search_term) ||
        item.name.toLowerCase().includes(search_term)
      );
    })
    .forEach((e) => {
      const li = document.createElement("li");
      li.innerHTML = `<i>Name:</i> ${e.name}  || <i>Country:</i> ${e.country}`;
      results.appendChild(li);
    });
};

showList();

search.addEventListener("input", (event) => {
  search_term = event.target.value.toLowerCase();
  showList();
});

              
            
!
999px

Console