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

166
Vistas
How to make an array of objects from dynamic values?

I have the following function

const extractTestCases = () => {
    const filterFile = files.filter(test => test.includes('.test.ts'))
    filterFile.forEach(testsuite => {
        const testSuites = fs.readFileSync(testsuite, { encoding: "utf8" });
        testCases.push(regexMatcher(testSuites, TestRegex, 1))
    })
    return testCases;
}

filterFile is an array for multiple files where I'm making forEach loop to extract some information from each file, what I want to do is to return an array of objects like this

[{"name of the file (testSuite)":["extracted value from this file regexMatcher(testSuites, TestRegex, 1)"]},{"testSuite2":["","",""]},...]
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try something like this :

const extractTestCases = () => {
        const filesArray = []
        const filterFile = files.filter(test => test.includes('.test.ts'))
        filterFile.forEach(testsuite => {
            const testSuites = fs.readFileSync(testsuite, { encoding: "utf8" });
            testCases.push(regexMatcher(testSuites, TestRegex, 1))
            filesArray.push({[testsuite]: regexMatcher(testSuites, TestRegex, 1)})
        })
        return filesArray;
    } 
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