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

90
Vistas
Filter function with 2 array sets

I am trying to achieve the same result as i wrote in below syntax by implementing filter function to my script.

The current script i have

    let sheet = [
        { $0: { 'Name': 'Report1' } },
        { $0: { 'Name': 'Row Count' } },
        { $0: { 'Name': 'Report2' } },
        { $0: { 'Name': 'User' } }
    ]

    let nope = ['User','Row Count','Container']
    let result = []

    for(let i = 0; i < sheet.length ;i++){
        if(sheet[i].$0.Name != nope[0] && sheet[i].$0.Name != nope[1] && sheet[i].$0.Name != nope[2]){
            result.push(sheet[i])
        }
    }
    
    console.log(result)

On my browser inspect element, it will result of (2) [{…}, {…}] on console.log

I tried using filter function

    let result_2 = sheet.filter(w => !w.$0.Name.includes(nope[0]))
    console.log(result_2)

1 : One problem and logic i face is that im unsure on how can i includes all the element of 'nope' in 'includes()'
2 : I will have to hard code the index such as nope[0] which i dont think is advisable if its going to be a big array

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

0

You actually almost finish but you reverse the w.$0.Name and nope.

let sheet = [
    { $0: { Name: "Report1" } },
    { $0: { Name: "Row Count" } },
    { $0: { Name: "Report2" } },
    { $0: { Name: "User" } },
];

let nope = ["User", "Row Count", "Container"];

let result_2 = sheet.filter(w => !nope.includes(w.$0.Name));

console.log(result_2);

PS: I think you should take a break and drink some tea. :)

about 4 years ago · Juan Pablo Isaza Denunciar

0

let result_2 = sheet.filter(w => !nope.includes(w.$0.Name))
about 4 years ago · Juan Pablo Isaza Denunciar

0

A simple and alternativr solution would be to use every() method within the filter. Like this:

It will check one element for every case of the second array and return true if nothing similar would be found.

 let result_2 = sheet.filter(w => nope.every(x=> x !== w.$0.Name))
    console.log(result_2)

let sheet = [{
    $0: {
      'Name': 'Report1'
    }
  },
  {
    $0: {
      'Name': 'Row Count'
    }
  },
  {
    $0: {
      'Name': 'Report2'
    }
  },
  {
    $0: {
      'Name': 'User'
    }
  }
]

let nope = ['User', 'Row Count', 'Container']
let result = []


let result_2 = sheet.filter(w => nope.every(x => x !== w.$0.Name))
console.log(result_2)

Or if you want to use includes() you can do this:

let result_3 = sheet.filter(w => !nope.includes(w.$0.Name))
    console.log(result_2)

let sheet = [{
    $0: {
      'Name': 'Report1'
    }
  },
  {
    $0: {
      'Name': 'Row Count'
    }
  },
  {
    $0: {
      'Name': 'Report2'
    }
  },
  {
    $0: {
      'Name': 'User'
    }
  }
]

let nope = ['User', 'Row Count', 'Container']
let result = []

let result_3 = sheet.filter(w => !nope.includes(w.$0.Name))
console.log(result_2)

Fiddle example

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