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

125
Vistas
JavaScript how to filter based on multiple values if the values arent empty

I am trying to filter based on multiple values and only if they are not empty. Example:

jobsTracked = [
        {
          "company": "Company1",
          "position": "Senior Frontend Developer",
          "role": "Frontend",
          "level": "Senior",
        },
        {
          "company": "Company2",
          "position": "Senior Frontend Developer",
          "role": "Frontend",
          "level": "Senior",
          
        }]

I am trying to filter by 3 values in this example: position, role, level. And if position is empty string then i dont want to filter it but still want to filter by role and level if they arent empty string. And vice versa for all of them. Can the JavaScript filter function do this?

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

0

When you say "filtering", you mean something like this?

let slot;

let role = 'Frontend';
let level = 'Senior';
let position = 'Senior Frontend Developer';

let filtered = [];
let length = jobsTracked.length;
for (let i = 0; i < length; ++i) {
    slot = jobsTracked[i]; 
    
    // "The Filter"
    if ((slot['role'] != '' && slot['role'] == role) &&
        (slot['level'] != '' && slot['level'] == level) &&
        (slot['position'] != '' && slot['position'] == position)) {
        filtered.push(slot);
    }
}

What this script does:

  1. It iterates over all elements of the array jobsTracked.
  2. It filters only those elements which the properties are not empty strings, and match the declared variables of the same name.
  3. Only the filtered elements are added to the filtered array.
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