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

104
Views
how to use 3 functions that return an object in javascript?

hey guys so i'm a beginning of javascript and I have a question... I have 3 functions let's say:

const a = (x, y, z) => {
 return {x, y, z}
}

const b = (a, b, c) => {
 return {a, b, c}
}

const c = (d, e, f) => {
 return {d, e, f}
}

let's say I want to make use of these return values in another function, so..

   const p = () => {
   const arr = [returned value from function a, returned value from function b, returned value from function c]
return arr
    }

how would I somehow use the objects that functions a, b, c in order to return an array of objects from function p?

thank you!

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

0

Following what you have asked:

const result1 = a(1, 'dog', null)
// result1 would be { x: 1, y: 'dog', z: null }

const result2 = b('cat', 2, null)
// result1 would be { a: 'cat', b: 2, c: null }

const result3 = c(3, 4, 'pig')
// result3 would be { d: 3, e: 4, f: 'pig' }

Therefore if you made the p function:

const p = () => {
    return [ a(1, 'dog', null), b('cat', 2, null), c(3, 4, 'pig') ]
}

const result1 = p()
// result1 would be: 
// [ 
//   { x: 1, y: 'dog', z: null }, 
//   { a: 'cat', b: 2, c: null }, 
//   { d: 3, e: 4, f: 'pig' } 
// ]

It would be far more likely that p would take some kind of arguments, then would use them inside. For example:

const p = (arg1, arg2, arg3) => {
     return [ a(arg1, arg2, arg3), b(arg1, arg2, arg3), c(arg1, arg2, arg3) ]
}

const result2 = p(1, 'dog' null)
// result2 would be:
// [ 
//   { x: 1, y: 'dog', z: null }, 
//   { a: 1, b: 'dog', c: null }, 
//   { d: 1, e: 'dog', f: null } 
// ]
about 4 years ago · Juan Pablo Isaza Report

0

const one = (a, b, c) => {
  return {a, b, c};
}

const two = (a, b, c) => {
  return {a, b, c};
}

const three = (a, b, c) => {
  return {a, b, c};
}

const result = () => {
  let firstObj = one(10,20,30);
  let secondObj = two(40,50,60);
  let thirdObj = three(70,80,90);
  // Returns all of the objects in an array.
  return [firstObj, secondObj, thirdObj];
}

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!