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

202
Views
How to add title/key to an array of multiple objects in javascript?

I have the following function, where its extracting some data from some files and return in an array

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

which gives me an output like the following

[
  {
    featureCustom: [ 'somethig' ]
  },
  {
    featureInsp: [
      'bla bla',
      'foo foo'
    ]
  }
]

how to make it generate an output like the following

[
    {
        "features": [
            {
                "featureCustom": [ 'somethig'
                ]
            },
            {
                "featureInsp": ['bla bla','foo foo'
                ]
            }
        ]
    }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Something like?...

const extractTestCases = () => {
    const filesArray = []
        filesArray.push({ [feature]: testCases })
    return [
      {
        features: 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!