-2

I am having two array

 var values[];
  var labels[];

How can i return these two variables and get from outsied the function.

krishna
  • 83
  • 2
  • 3
  • 11

3 Answers3

2

You can return them in an object literal:

function yourFunction() {
  var values = [];
  var labels = [];
  //code that modifies `values` and `labels`
  return { values : values, labels : labels };
}

var a = yourFunction(); //`a.values` is `values` from the function and `a.labels` is `labels` from the function
go-oleg
  • 19,272
  • 3
  • 43
  • 44
0

Return an object or array containing these two variables.

return [
    values[],
    labels[]
];
dooplenty
  • 124
  • 7
0

A function can return one value/object/array at a time. Now you can do it in smarter way. Use nested Array here.

Put both array inside another array and return that array

var newAr = {};
newArr.push(values)
newArr.push(labels)
return newArr

There are many other ways to create jQuery Array. Refer jQuery Arrays for that.

Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101