I am trying to return value from my customer function but the problem is I am getting single value
customerDetails.js
function customerDetails(obj, customerId) {
let type, access_id, info, entry_available;
for (i = 0; customerId[obj.data.target.sys.id].locale.length > i; i++)
for (const detail of customerId[obj.data.target.sys.id].locale) {
type = obj.member;
access_id = obj.id.replace(/-/g, "_");
info = obj.info;
entry_available = {};
if (obj.data.target.sys.id in customerId) {
entry_available = {
"customer-id": obj.data.target.sys.id,
locale: detail,
"shop-id": customerId[obj.data.target.sys.id].shop_id,
};
}
// console.log( access_id, type, entry_available, info ); // here I am getting all the values
return { access_id, type, entry_available, info };
}
}
so here you can the place where I am writing console.log() I am getting all the values there so I return the value as I want to return exactly the same way but It returning single value is there any possible way I can return all the values which I am getting in same format ?
assuming, that you want to have your values returned in single variables:
there is no way to return multiple values plain in javascript like it is possible in, i believe, python, but you can use destructuring to your advantage.
function customerDetails ( obj, customerId ) {
let type, id, info;
// ...
return { type, id, info };
}
const { type, id, info } = customerDetails(/* ... */);
read more about destructuring here