-2

I am having two array

 var values[];
  var labels[];

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

1

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

Comments

0

Return an object or array containing these two variables.

return [
    values[],
    labels[]
];

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.