Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!