Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to return multiple values from function in Node.js

4 Answers

0 votes
function f() { 
    const a = 9;
    const b = 4;
    const c = 398;
  
    return [a, b, c];
} 
  
const arr =  f();
  
const x = arr[0];
const y = arr[1];
const z = arr[2];
  
console.log(x, y, z); 
  
  
  
  
/*
run:
  
9 4 398
  
*/

 



answered Dec 31, 2021 by avibootz
0 votes
const [x, y, z] = (function(){ return [5, 98, 2]; })();
           
console.log(x, y, z); 
  
  
  
/*
run:
  
5 98 2
  
*/

 



answered Dec 31, 2021 by avibootz
0 votes
const {x, y, z} = (function(){ return {x: 95, y: 2, z: 8} })();
          
console.log(x, y, z); 
 
  
  
  
/*
run:
  
95 2 8
  
*/

 



answered Dec 31, 2021 by avibootz
0 votes
const f = function() {
    const a = 22;
    const b = 95;
    const c = 100;
    return {
        vala: a,
        valb: b,
        valc: c
    };
};
  
const rv = f();
  
const x = rv.vala;
const y = rv.valb;
const z = rv.valc;
           
console.log(x, y, z); 
  
 
  
  
  
/*
run:
  
22 95 100
  
*/

 



answered Dec 31, 2021 by avibootz

Related questions

...