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

90
Views
Cómo sacar una cadena de List js

Soy bastante nuevo en JS y estoy tratando de codificar un bot de discordia. Ahora tengo una pregunta:

Si tengo una lista como esta:

 { 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

algo como

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

debería hacer el truco

lea sobre Array.filter para obtener más información

about 4 years ago · Santiago Gelvez Report

0

Puede usar el método de filtro para filtrar elementos seleccionados.

 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

A juzgar por el título, solo desea una matriz de cadenas de los nombres de los comandos.

 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!