Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda