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

180
Visualizações
Chat Messages Will Not Send With Filter

Me and my friend are making a chat room for students at our school to use during free time and stuff. I am trying to add a filter so that it will remain SFW. I am very new to JavaScript so when I added the filter you couldn't send messages in the chat anymore. However when I make the filter script a comment and disable it, the messages send just fine.

Filter Code:

    var array = array.js
message.replace(array, "****");

Messaging Code:

        if (message && connected) {
  $inputMessage.val("");
  addChatMessage({
    username: username,
    message: message
  });

  socket.emit("new message", message);
}}

My friend is responsible for the Messaging code since he is much more experienced at JavaScript, but he is very busy and can't add it right now so I am trying to.

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

0

Assuming you have a array to filter which is array you could split your message by white space and then check each word to see if it contains a bad word.

Two methodologies (FYI neither is perfect. both of these solutions have plenty of edge cases/loopholes: I'd recommend a js package that has more thought put into it npm: bad-words, npm: censor-sensor, or npm: swearjar)

Both split the message message.split(' ') and then iterate over each word to see if it needs replacing .map. The first checks to see if the current word is in array and the second sees if array words contain the current word, then if so replace with ****

const array = ['badword', 'nsfw']

let message = 'my message is full of badwords which may be nsfw'

message = message.split(' ').map(word => array.includes(word.toLowerCase()) ? '*****' : word).join(' ')

console.log(message)

message = 'my message is full of badwords which may be nsfw'

message = message.split(' ').map(word => array.some(nsfword=>word.toLowerCase().includes(nsfword)) ? '*****' : word).join(' ')

console.log(message)

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