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

129
Vistas
Looping through an array of arrays and removing an item

My question is quite odd because it's for OfficeScripts. I am pretty sure it is Javascript-based because that is what I have been writing in. Now onto my question. I have an array of arrays that I am backward looping through in order to remove some items. basically, I gathered row data from one table and then used it to filter other tables, and then built an array of an array using both data. looking something like this:

const Data = [["Name", "Area", "Position", "Shift"]];
const otherData = [["Training A","Course A","Level","Curricula"],["Training B","Course B","Level","Curricula"],["Training C","Course C","Level","Curricula"]];
var CombinedData = otherData.map(x=>[...Data[0], ...x]);
console.log(CombinedData);

What I am looking to accomplish is to remove the "Position" from every array in the CombinedData array of arrays. Right now I am writing this and it's emptying my array:

const Data = [["Name", "Area", "Position", "Shift"]];
const otherData = [["Training A","Course A","Level","Curricula"],["Training B","Course B","Level","Curricula"],["Training C","Course C","Level","Curricula"]];
    var CombinedData = otherData.map(x=>[...Data[0], ...x]);
    console.log(CombinedData);
    
    for(let i = CombinedData.length -1; i>=0; i--){
      if(CombinedData[i][2] == Data[0][2]){
        CombinedData[i].splice(i,1);
          
      }
    }
    console.log(CombinedData);
  
    
What I would like the end output to look like is

CombinedData= [["Name", "Area", "Shift","Training A","Course A","Level","Curricula"],["Name", "Area", "Shift","Training B","Course B","Level","Curricula"],["Name", "Area", "Shift","Training C","Course C","Level","Curricula"]];

Which obviously isn't working. Any thoughts on what I need to do? JavaScript isn't my strongest language, and I am completely new to OfficeScripts. I appreciate any help.

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

0

Issue is with splice(i, 1), This should be splice(2, 1) since you need to remove the 2 (indexed) item.

const Data = [["Name", "Area", "Position", "Shift",]];
const otherData = [["Training A","Course A","Level","Curricula"],["Training B","Course B","Level","Curricula"],["Training C","Course C","Level","Curricula"]];
    var CombinedData = otherData.map(x=>[...Data[0], ...x]);
    
    for(let i = CombinedData.length -1; i>=0; i--){
      if(CombinedData[i][2] == Data[0][2]){
        CombinedData[i].splice(2,1);
          
      }
    }
    console.log(CombinedData);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you only ever use element 0 of Data, just filter that once and use that in your combination:

const Data = [["Name", "Area", "Position", "Shift",]];
const otherData = [["Training A","Course A","Level","Curricula"],["Training B","Course B","Level","Curricula"],["Training C","Course C","Level","Curricula"]];
var elem0 = Data[0].filter( y => y != "Position" )
var CombinedData = otherData.map(x=>[...elem0, ...x]);
console.log(CombinedData);

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