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

113
Visualizações
how can I filter BlockList?

First, I'm not an English speaker. I'm a beginner developer. Please understand if my English is awkward

I'm creating a real-time chat app and filtering messages from the person I blocked So I'm filtering through the target number of the blocked person in the entire message. But this filter process is not working well. Can you help me?

  1. Messages come in the form of object arrangement from the server.

like this


Message :  [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

{type: 'message', idx: 1313231, name: '%E3%85%81%E3%84%B4%E3%85%87%E3%85%81', message: 'hello'}

https://i.stack.imgur.com/vMur3.png

  1. Similarly, the block list is also received in the form of an object array from the server.

idx is user's idx target is blocked idx

blockList 
   [{…}]
 > 0: {idx: 1321, target: 2231, timestamp: 1644561250499}
    length: 1
[[Prototype]]: Array(0)

https://i.stack.imgur.com/eLnYQ.png

So I want filtering that message if blockList.target !== enterMsg.idx but it's not working so I tried some ways that is

  const blockMap = blockList.map((el) => el.target)

 const filterdMessage  = () => {enterMsg.filter((msg)=> {
   const realfiltered = enterMsg.filter((el) => {
    blockMap.map((bl) => {
      return el.idx !== bl
    })
   })
    })};

but it is empty array How can i fix it ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would say there is a misunderstanding of the array functions: maybe you should check the docs ;)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

Then you want to filter an array (the list of message) and the filter function must return a boolean so you probably want something like that :

const filterdMessage  = enterMsg.filter((msg)=> {
  return !blockList.some((bl) => {
     return msg.idx === bl.target
  })
})

What we do here is :

  • tell that we want to filter the enterMsg array based on a condition that will be computed in the provided callback
  • for each message check if no entry in the block list has a target matching its idx

we use 'some' function that will return true if a matching block is found, and since we dont want matching blocks we negate the condition

about 4 years ago · Juan Pablo Isaza 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