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

118
Views
Merge different Array variables value into JSON Object

I have below respective variables holding the bill# in an array.

billA = [12345]  // For "Pizzahut" Billsystem 

billB = [96754,75432]  // For "Subway" Billsystem

billC = [63946]   // For "XYZ" Billsystem

I intend to combine the above values into a JSON object like the below format.

Result Output:

{"BillDetails" : [{billsystem: "PizzaHut" , billnum: "12345"}, {billsystem : "Subway" , billnum "96754" }, {billsystem : "Subway" , billnum "75432"},{billsystem : "XYZ" , billnum "63946"}]}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const obj = {
   "BillDetails" : [
       ...billA.map(item=>({billsystem: "PizzaHut" , billnum: String(item)})),
       ...billB.map(item=>({billsystem: "Subway" , billnum: String(item)})),
       ...billC.map(item=>({billsystem: "XYZ" , billnum: String(item)})),
   ]
}
about 4 years ago · Juan Pablo Isaza Report

0

You could use flatMap along with an array of billing systems

let billA = [12345] // For "Pizzahut" Billsystem 
let billB = [96754, 75432] // For "Subway" Billsystem
let billC = [63946] // For "XYZ" Billsystem
let billD = [] // For "Testing" Billsystem
let types = ["Pizzahut", "Subway", "XYZ", "Testing"]
let json = {
  BillDetails: [billA, billB, billC, billD].flatMap((e, i) => (e?.map(b => ({
    billSystem: types[i],
    billNum: b
  }))))
}

console.log(json)

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!