Skip to content

Files

Latest commit

author
vanntile
Jan 31, 2019
b9fc9a6 · Jan 31, 2019

History

History
This branch is 320 commits ahead of, 380 commits behind wesbos/JavaScript30:master.

06 - Type Ahead

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jan 31, 2019
Jan 31, 2019
Jan 31, 2019
Nov 29, 2018

Type Ahead

This tutorial shows how to filter data for a quick search type ahead.

![06 - Type Ahead](../assets/img/06 - Type Ahead.png)

Learning notes

Some concepts taught:

  • managing Promises with fetch
  • ES6 aray spreading
  • RegEx string filter
  • using Array.prototype.map to turn data into HTML nodes
  • inserting generated nodes with element.innerHTML
// turn matched data to a node and then joining it to a string

const html = matchArr.map(place => {
    const cityName = place.city.replace(regex, `<span class="hl">${this.value}</span>`)
    const stateName = place.state.replace(regex, `<span class="hl">${this.value}</span>`)

    return `
        <li>
        <span class="name">${cityName}, ${stateName}</span>
        <span class="population">${numberWithCommas(place.population)}</span>
        </li>
    `
}).join('')