Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

155
Vistas
Filtrar una matriz de objetos de una matriz dinámica

Tengo esta matriz fija:

 x = [ {value: 0, text: "hello world"}, {value: 1, text: "how are you?"}, {value: 2, text: "no problem"} {value: 3, text: "anything else?"} {value: 4, text: "other dummy text"} ]

y otra matriz dinámica:

 y = [2, 4]

Me gustaría filtrar la matriz "x" según los valores de la matriz "y"

el resultado esperado debe ser:

 x = [ {value: 2, text: "no problem"}, {value: 4, text: "other dummy text"} ]

¿Cómo podría hacer esto?

Gracias

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Después de obtener el valor de matriz dinámica. Puede ejecutar el código de esta manera, filtra la matriz para el valor de la matriz dinámica

 let x = [ {value: 0, text: "hello world"}, {value: 1, text: "how are you?"}, {value: 2, text: "no problem"}, {value: 3, text: "anything else?"}, {value: 4, text: "other dummy text"} ]; const y=[2,4]; x = x.filter( data => (y.includes(data.value))); console.log(x);

about 4 years ago · Juan Pablo Isaza Denunciar

0

lo que está buscando es filtrar la matriz x y verificar si sus valores están incluidos en la matriz y

 const x = [ { value: 0, text: "hello world" }, { value: 1, text: "how are you?" }, { value: 2, text: "no problem" }, { value: 3, text: "anything else?" }, { value: 4, text: "other dummy text" } ]; const y = [2, 4]; const result = x.filter((item) => y.includes(item.value)); console.log(result);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Ahí tienes

 x = [ {value: 0, text: "hello world"}, {value: 1, text: "how are you?"}, {value: 2, text: "no problem"}, {value: 3, text: "anything else?"}, {value: 4, text: "other dummy text"} ] y = [2, 4] z = [] for (var i = 0;i<x.length;i++){ for (var j = 0;j<y.length;j++){ if (x[i].value == y[j]){z.push(x[i])} } } console.log(z)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda