I try to receive from a helperUtils file, the value that i get in a function. In this function first i call to backend to get some information (this works perfect), then with this value (is an array of data) i do somethings inside te function to return a new value.
When i call this function from my .jsx file and try to receive the final value, i receive Promise in my console when i do a console.log.
function inside Helperutils.js
export const getResponseId = async (idStart) => {
const res = await getResponsIdApiNew(idStart);
if (res.length === 0) {
return (idStart + "1");
} else {
let numbersArray = [];
for (let j = 0; j < res.length; j++) {
if (res[j].substring(idStart.length, res[j].length)[0] !== "") {
numbersArray.push(Number(res[j].slice(idStart.length, res[j].length)));
}
}
if (numbersArray.length !== 0) {
const max = Math.max(...numbersArray);
let exist = false;
for (let i = 1; i <= max; i++) {
if (!res.includes(idStart + i)) {
exist = true;
idStart = idStart + i;
console.log(idStart); //give me the value that i want
break;
}
}
if (exist) {
console.log(idStart); //give me the value that i want
return (idStart);
} else {
let number = max + 1;
console.log(idStart + number)
return (idStart + number);
}
}
}
};
in my file.jsx:
i did try:
const getNewIdResponse = async () => {
await getResponseId(`${getTopic}_${typeResponseTitle}_`);
};
console.log(getNewIdResponse);
and try:
const getNewIdResponse = getResponseId(`${getTopic}_${typeResponseTitle}_`);
console.log(getNewIdResponse);
all consoles print: