У меня есть этот объект
let x = {
"name": "Ola",
"dates": [
{
"7.01.2020": [1, 2, 3]
},
{
"8.01.2020": [3 ,4]
}
],
"id": 7
}
, и мне нужно иметь возможность удалять по нажатию кнопки выбранный элемент из массива. Ex. после нажатия кнопки мой объект выглядит следующим образом:
let x = {
"name": "Ola",
"dates": [
{
"7.01.2020": [1, 2]
},
{
"8.01.2020": [3 ,4]
}
],
"id": 7
}
Обычно мне удается отфильтровать этот arr, проблема в том, что я пытаюсь вернуть новый x.dates arr. Обратите внимание, что есть объекты с разными ключами.
Есть идеи? Спасибо!
РЕДАКТИРОВАТЬ - все веселье c
try {
fetch(`http://localhost:3003/users/${userObject.id}`)
.then(res => res.json())
.then(user => {
const map = new Map(
user.dates.map((entry, i, arr) => {
const [key] = Object.keys(entry);
console.log(entry);
return [key, entry[key]];
})
);
result = map.get(date.toLocaleDateString());
console.log(user.dates);
return user;
})
.then(user => {
// Create array without deleted task
userDatesArr = result.filter(el => {
if (el !== itemText) {
return el;
}
});
result = userDatesArr;
// Update json-server - doesn't work, cause user.dates looks the same
patchFunc(user.dates);
});
} catch (err) {
console.error(err);
}
;