Difference between revisions of "World Factbook"
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
==Get a button for each letter== | ==Get a button for each letter== | ||
* Show a button for each letter that a country can begin with | * Show a button for each letter that a country can begin with | ||
* You can use a [Set|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set] to remove duplicates from a list. | * You can use a [[Set|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set]] to remove duplicates from a list. | ||
<div class=qu> | <div class=qu> | ||
<pre class=usr> | <pre class=usr> |
Revision as of 09:25, 22 January 2022
Get a button for each letter
- Show a button for each letter that a country can begin with
- You can use a https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set to remove duplicates from a list.
fetch('/worldl.json') .then((r)=>r.json()) .then((r)=>{ let letters = r.map(c=>c.name[0]); for(let a of letters){ let b = document.createElement('button'); b.innerText = a; document.body.append(b); } });
fetch('/worldl.json') .then((r)=>r.json()) .then((r)=>{ let letters = new Set(r.map(c=>c.name[0])); for(let a of letters){ let b = document.createElement('button'); b.innerText = a; document.body.append(b); } });