Within my JSON file, there is an array structured like this:
{
"commands": [
{
"user": "Rusty",
"user_id": "83738373",
"command_name": "TestCommand",
"command_reply": "TestReply"
}
]
}
I have a requirement to restrict the number of commands for each user (identified by their user_id
) to a maximum of 3. I understand that I need to iterate through each object in the array, but I am unsure how to proceed from there.
The desired outcome would resemble something like this:
for (let i = 0; i < arrayOfCommands.commands.length; i++) {
if (arrayOfCommands.user_id appears more than 3 times) {
return message.reply("You cannot create more than 3 commands.");
}
}