const letter = prompt(`What do you want?`).toLowerCase();
const array = ['bread','milk','apple', 'juice','banana','peach', 'pineapple','beer','Putin'];
const result = array.filter((item) => item.toLowerCase().includes(letter));
alert(result);
const letter = prompt(`What do you want?`).toLowerCase();
const array = ['bread','milk','apple', 'juice','banana','peach', 'pineapple','beer','Putin'];
const result = [];
array.map((item) => {
if (item.toLowerCase().includes(letter)) {
result.push(item);
}
});
alert(result);
var bestAlbumsByGenre = {
"Country": ["JohnyCash", "PatsyChine"],
"Rock": []
}
// --------------------------- ИЗ ПЕРВОГО КОМПОНЕНТА ---------------------------
return(
<>
<Info />
<Form weatherMethod={gettingWeather} />
<Weather />
</>
)
// --------------------------- ИЗ ВТОРОГО КОМПОНЕНТА ---------------------------
function Form({weatherMethod}) {
return(
<form onSubmit={weatherMethod}>
<input type="text" name="city" placeholder="Город"/>
<button>Получить погоду</button>
</form>
)
}
import {useState, useCallback} from 'react';
export default () => {
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);
const request = useCallback(async (url, method = `GET`, body = null, headers = {}) => {
setLoading(true);
try {
if (body) {
body = JSON.stringify(body);
headers[`Content-Type`] = `application/json`;
}
const response = await fetch(url, { method, body, headers });
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Something went wrong');
}
setLoading(false);
return data;
} catch (e) {
setLoading(false);
setError(e.message);
throw e;
}
}, []);
const clearError = useCallback(() => setError(null), []);
return {loading, request, error, clearError}
}
const {loading, request, error, clearError} = useHttp();
const handler = async () => {
const response = await request(`/api/auth/login`, `POST`, {...form}); // можно четвертым передать headers
}
if (loading) {} // если грузятся данние
if (error) {} // если прозойшла ошибка
const links = document.querySelectorAll(`header nav a`);