const arr = Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.map(n => n[0]);
const arr = Object
.values(Object.entries(obj).reduce((acc, n) => ((acc[n[1]] ??= []).push(n[0]), acc), {}))
.reverse()
.flat();
При таком коде
.then(res => res.ok ? res.json() : Promise.reject(res.text()))
И еще такой вопрос:
.then(res => res.json())
.then(res => res.users)
почему нельзя сразу возвратить users, вот так?
.then(res => res.json().users)
Body.json()
Takes a Response stream and reads it to completion. It returns a promise that resolves with the result of parsing the body text as JSON, which is a JavaScript value of datatype object, string, etc.
fetch('http://localhost:3001/register', {
method: 'post',
body: data
})
.then(response => {
if (!response.ok) {
throw new Error('my api returned an error')
}
return response.json()
})
.then(user => {
console.log(user)
})
<div style="width: 100%; background-color: #fff;">
<button style="width: 100%;height: 50px;">
Зарегистрироваться
<div style="background-size: 20px 20px;background-repeat: no-repeat; background-position: right 0 center;background-image: url(https://img2.freepng.ru/20180325/qaw/kisspng-email-computer-icons-clip-art-coin-5ab83d2671f511.2388637315220237184668.jpg);"></div>
</button>
</div>
Alex, есть карточка, при клики на нее, открывается полная ее версия, и у этой карточки есть лайк. Так вот когда я лайк ставлю, у меня открывается полная карточка и ставится лайк, а мне нужно только лайк
str.match(/^\S*$/) вернет false если есть пробелы
str.match(/^\S{5,}$/)