Convert between currencies using the Frankfurter API for live exchange rates.
Code
Utilitiesconst res = await fetch(
`https://api.frankfurter.app/latest?amount=${amount}&from=${from}&to=${to}`
);
const data = await res.json();
return `${amount} ${from} = ${data.rates[to]} ${to}`;Parameters
Amount to convert.
Source currency code.
Target currency code.
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Array to Object
Convert an array of key-value pairs to an object using Object.fromEntries.
Camel Case to Words
Convert a camelCase string to separate words by inserting spaces before capitals.
CSV to JSON
Convert a CSV string to a JSON array of objects with headers as keys.
Decimal to Octal
Convert a decimal number to its octal string representation.
Integer to Roman
Convert integer to Roman numeral.
JSON to CSV
Convert JSON array to CSV string.