I am extracting json value from json response and storing it into array and returning same array but value is getting undefind. Where as in setup function I am able to print value.
export function setup() {
let code = [];
code = object.func_name();
code.push();
console.log('code:::' + code); // code::: 92409391-4d82-8028-5yy
return code;
}
export function abc(code) {
console.log('code: ' + code);
}
export default function(code) {
console.log('code1: ' + code);
}
getting TypeError: Cannot read property 'push' of undefined this error. But when I changed push functionality -
if (!Array.isArray(authcode)) {
authcode = [];
}
authcode.push();
I'm getting value undefined in abc and default functions for code.
You are overwriting the array
let code = []
with whateverobject.func_name()
returns, probably some object, when you should return simple data fromsetup()
.Keep in mind that each VU in k6 is a different JavaScript runtime, and
setup()
is executed in its own separate runtime as well, so you can return an object with methods and such, only plain data. The data returned fromsetup()
is essentially serialized to JSON and then unserialized in each VU.