-5

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()">

How to show the letter 'b' when I click the button ?

Phil
  • 157,677
  • 23
  • 242
  • 245

2 Answers2

2

You can achieve that like this.

function ABC(){
  const {rr} = getPassedUsers();
  console.log(rr[1]);
};
0

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
}
Mreza0100
  • 328
  • 1
  • 9