Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda