0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javascript演習 6日目/30日

Last updated at Posted at 2021-10-20

覚えたこと

fetch()はpromise
push()にスプレッド構文

fetch(endpoint)
  .then(blob => blob.json())
  .then(data => cities.push(...data));

filterとmatch()
new RegExp()

cities.filter(place => {
  const regex = new RegExp(word,'gi');
  return place.match(regex)
});

inputにchangeとkeyup

searchInput.addEventListener('change' , displayMatches);
searchInput.addEventListener('keyup' , displayMatches);

replace()

const regex = new RegExp(this.value, 'gi');
place.replace(regex,`<span class="hl">${this.value}</span>`)

map()に${}して、htmlを書き換える
join()

const html = matchArray.map(place => {
    return `
    <li>
      <span class="name">${place.city},${place.state}</span>
      <span class="population">${place.population}</span>
    </li>
    `;
  }).join('')
  suggestions.innerHTML = html;

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?