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

116
Views
Split an array into an array with different objects

I was working on a plain array but I want the structure of the array to be in a sub-array form with multiple entries inside it. I tried forEach but when I push the element the whole array is pushed inside the sub-array. The array that I have

data = ["1640662522","1640663240","1640663967","1640664659","1640665388","1640666124","1640666829","1640667505","1640668278","1640668984"];

but I want the structure of my new array to be

    {
"sizeData":[
 {
           "timestamp":1640662522,
           "size":12345,
           "fees":12589,
           "cost":168
},
 {
           "timestamp":1640663240,
           "size":12345,
           "fees":12589,
           "cost":168},
 {
           "timestamp":1640663967,
           "size":12345,
           "fees":12589,
           "cost":168
}, {
           "timestamp":1640664659,
           "size":12345,
           "fees":12589,
           "cost":168
}
]

Could anyone help me on this. I am working on js for this

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just do it.

Step 1: Create new array elements

Step 2: ForEach data and push data to array elements

Step 3: Standardized data.

Good luck!

let data = ["1640662522","1640663240","1640663967","1640664659","1640665388","1640666124","1640666829","1640667505","1640668278","1640668984"];
let elements = [];
data.forEach(function(val){
  elements.push({
    "timestamp":parseInt(val),
    "size":12345,
    "fees":12589,
    "cost":168
  })
})
let result = {
  "sizeData": elements 
}
console.log(result) 

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!