✅ – _mercury – 00-13 Aug 29

I have logged group as in the photo I have this code
groups.forEach((group) => {
console.log(group);

return Object.keys(group).forEach((key) => {
if (!group[key]) {
delete group[key];
}
});
});
groups.forEach((group) => {
console.log(group);

return Object.keys(group).forEach((key) => {
if (!group[key]) {
delete group[key];
}
});
});
But these 2 lines do not work
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
why ?
M
_mercury599d ago
full code
groups.forEach((group) => {
console.log(group);
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
return Object.keys(group).forEach((key) => {
if (!group[key]) {
delete group[key];
}
});
});
groups.forEach((group) => {
console.log(group);
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
return Object.keys(group).forEach((key) => {
if (!group[key]) {
delete group[key];
}
});
});
UU
Unknown User598d ago
M
_mercury598d ago
@Timotius
UU
Unknown User598d ago
M
_mercury598d ago
{
"groups": [
{
"id": 8,
"name": "Cases",
"created_at": "2022-08-27T21:28:02.000Z",
"updated_at": "2022-08-27T21:28:02.000Z",
"attributes": [
{
"id": null,
"name": null
}
],
"templates": [
{
"id": null,
"name": null
}
]
}
]
}
{
"groups": [
{
"id": 8,
"name": "Cases",
"created_at": "2022-08-27T21:28:02.000Z",
"updated_at": "2022-08-27T21:28:02.000Z",
"attributes": [
{
"id": null,
"name": null
}
],
"templates": [
{
"id": null,
"name": null
}
]
}
]
}
UU
Unknown User598d ago
M
_mercury598d ago
mmm , it is not the code i seek
UU
Unknown User598d ago
M
_mercury598d ago
they are numbers surronded by quotes I am trying to parseInt them
groups.forEach((group) => {
console.log(group);

return Object.keys(group).forEach((key) => {
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
if (!group[key]) {
delete group[key];
}
});
});
groups.forEach((group) => {
console.log(group);

return Object.keys(group).forEach((key) => {
group.templates_count = parseInt(group.templates_count) || 0;
group.attributes_count = parseInt(group.attributes_count) || 0;
if (!group[key]) {
delete group[key];
}
});
});
I have did that BUT it works for attributes_count BUTTTTTT templates_count disappears , i dunno why
{
"id": 8,
"name": "Cases",
"created_at": "2022-08-27T19:28:02.000Z",
"updated_at": "2022-08-27T19:28:02.000Z",
"attributes": [
{
"id": null,
"name": null
}
],
"templates": [
{
"id": null,
"name": null
}
],
"attributes_count": 0
}
{
"id": 8,
"name": "Cases",
"created_at": "2022-08-27T19:28:02.000Z",
"updated_at": "2022-08-27T19:28:02.000Z",
"attributes": [
{
"id": null,
"name": null
}
],
"templates": [
{
"id": null,
"name": null
}
],
"attributes_count": 0
}
UU
Unknown User598d ago
M
_mercury598d ago
thx for effort BUT i am also doing that
if (!group[key]) {
delete group[key];
}
});
if (!group[key]) {
delete group[key];
}
});
UU
Unknown User598d ago
M
_mercury598d ago
bc the value is null
UU
Unknown User598d ago