_mercury
_mercury2y ago

✅ – _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 ?
15 Replies
_mercury
_mercury2y 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];
}
});
});
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y ago
@Timotius
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y 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
}
]
}
]
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y ago
mmm , it is not the code i seek
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y 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
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y ago
thx for effort BUT i am also doing that
if (!group[key]) {
delete group[key];
}
});
if (!group[key]) {
delete group[key];
}
});
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
_mercury
_mercury2y ago
bc the value is null
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
reactibot
reactibot2y ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1013602157473304616 This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1013602157473304616