Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
How to get string out of List js

I am pretty new to JS and I am trying to code a discord bot. Now i have a question:

If i have a list like this:

    {
      names: [ 'kick' ],
      category: 'Moderation',
      description: 'Kicks a user',
      syntax: '<User> <Reason>',
      hidden: false,
      testOnly: true
    }
    {
      names: [ 'send' ],
      category: 'Config',
      description: 'Sends a message.',
      syntax: '<channel> <text>',
      hidden: false,
      testOnly: true
    }
    {
      names: [ 'timeout' ],
      category: 'Moderation',
      description: 'Times out a user',
      syntax: '<User> <Time>',
      hidden: false,
      testOnly: true
    }``` (this is all a variable)
how can i get for example every command that has the Moderation catagory?
So that i have them in an array.
about 4 years ago · Santiago Gelvez
3 answers
Answer question

0

something like

list.filter(x=>x.category==="Moderation")

should do the trick

please read up on Array.filter to learn more

about 4 years ago · Santiago Gelvez Report

0

You can use filter method to filter selectedItems.

var myList =     {
      names: [ 'kick' ],
      category: 'Moderation',
      description: 'Kicks a user',
      syntax: '<User> <Reason>',
      hidden: false,
      testOnly: true
    }
    {
      names: [ 'send' ],
      category: 'Config',
      description: 'Sends a message.',
      syntax: '<channel> <text>',
      hidden: false,
      testOnly: true
    }
    {
      names: [ 'timeout' ],
      category: 'Moderation',
      description: 'Times out a user',
      syntax: '<User> <Time>',
      hidden: false,
      testOnly: true
    }
var selectedCommands = myList.filter(value => value.category == 'Moderation')
about 4 years ago · Santiago Gelvez Report

0

Judging from the title you only want a string array of the command names.

let disCommands = [ { names: [ 'kick' ], category: 'Moderation', description: 'Kicks a user', syntax: '<User> <Reason>', hidden: false, testOnly: true }, { names: [ 'send' ], category: 'Config', description: 'Sends a message.', syntax: '<channel> <text>', hidden: false, testOnly: true }, { names: [ 'timeout' ], category: 'Moderation', description: 'Times out a user', syntax: '<User> <Time>', hidden: false, testOnly: true } ]

let modCommands = disCommands.filter(c => c.category === 'Moderation').flatMap(c => c.names);
console.log(modCommands);

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!