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

202
Visualizações
Return Array Instead of String

I am trying to get an array response from my getTeam() function so I can properly filter my DataTable to show more than one team for the current Player (if they are on more than one team).

DataTables Filter:

  $.fn.dataTable.ext.search.push( //creating my own filter function for the table
        function(settings, searchData, index, rowData, counter, statusClass) { 

            var userName = searchData[1]; //created a var to search through the 3rd column (0 index) which contains all of the Monday Dates
            var searchTeam = searchData[0];
            // Get Datatables API
            var api = $.fn.dataTable.Api('#myTable'); 
            if (settings.sTableId === 'myTable' ) {
            if(userName === thisUserTitle){
            return true;
            } else {
              return false;
           }
           
          }
          if (settings.sTableId === 'certificateTable' ) {
            if(currentTeam === searchTeam){
            return true;
            } else {
              return false;
           }
           
          }
          return true;
        }
    );

The original snippet that returns just the first team:

var teamData = [{
  "Team" : "Team 1",
  "Players" :[ 
    "Beerus Dev",
    "Goten Dev",
    "Trunks Dev",
    "Majin Bu Dev"

  ]
},
{
  "Team" : "Team 2",
  "Players" : [
    "Beerus Dev",
    "Shap Dev",
    "Krillin Dev"
  ]
}
];


function getTeam() {

  const team = teamData.find(team => team.Players.includes(currentUser));
  return team.Team;
}

var currentUser = "Beerus Dev";
var currentTeam = getTeam(currentUser);
 
console.log(currentTeam);
 

To get the array response, I have tried using the .filter() as opposed to the .find() but I end up getting an empty array as my response.

var teamData = [{
  "Team" : "Team 1",
  "Players" :[ 
    "Beerus Dev",
    "Goten Dev",
    "Trunks Dev",
    "Majin Bu Dev"

  ]
},
{
  "Team" : "Team 2",
  "Players" : [
    "Beerus Dev",
    "Shap Dev",
    "Krillin Dev"
  ]
}
];

var currentUser = "Beerus Dev";

const team = teamData.filter(function(team, i){
    return teamData[i].Players.includes(currentUser);
})

console.log(team)

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

0

Simplify this code:

var teamData = [{
  "Team" : "Team 1",
  "Players" :[ 
    "Beerus Dev",
    "Goten Dev",
    "Trunks Dev",
    "Majin Bu Dev"

  ]
},
{
  "Team" : "Team 2",
  "Players" : [
    "Beerus Dev",
    "Shap Dev",
    "Krillin Dev"
  ]
}
];

var currentUser = "Beerus Dev";
const team = teamData.filter(team => team.Players.includes(currentUser)).map(team => team.Team);

console.log(team)

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