用習慣 python 之後, 覺得 c/java/javascript 不能回傳2個變數覺得麻煩, 在 javascript 可以用 array 或 dictionary 包起來傳, 收到後再解開.
//dictionary object sample:
function getNames() {
// get names from the database or API
let firstName = 'John',
lastName = 'Doe';
return { firstName, lastName };
}
let names = getNames();
let firstName = names.firstName,
lastName = names.lastName;
// or by this way.
let { firstName, lastName } = getNames();