Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
76 views
in Technique[技术] by (71.8m points)

How to return the array variables values to another function on javascript?

function getPassedUsers() {
  var rr = ['a', 'b'];
  var xx = ['c'];
  return { rr, xx };
}

function ABC() {
  // i want to show letter 'b'
  console.log(rr[1]);
};
<input type="button" onClick="ABC()">
question from:https://stackoverflow.com/questions/65930734/how-to-return-the-array-variables-values-to-another-function-on-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

My suggestion for you: free code camp

function getPassedUsers() {
    var rr = ["a", "b"];
    var xx = ["c"];

    return {
        rr: rr,
        xx: xx,
    };
}

function ABC() {
    var data = getPassedUsers();
    console.log(data.rr);
    console.log(data.xx);
    // you should first call `getPassedUsers` function
    // so `getPassedUsers` generate that data and return it for you
    // and you will save it in `data` var
    // if you want data from `getPassedUsers` you should call it first
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...