Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop through Array and return result into Array

I have this array:

var shareholders = [“name1”, “name2”, “name3”];

This is function from HPSM that is fetching data from that array:

function getShareholders(RECORD)
 {
  var fShareholder = new SCFile("device");
  var rc = fShareholder.doSelect("logical.name=\"" + RECORD + "\"");
  if (rc == RC_SUCCESS)
  {
    print(fShareholder.shareholder_contacts);
    return fShareholder.sharholder_contacts;
    }
 return null;
}

It returns them in array form but I need it to fetch one by one:

var users = new Array();
users[0] = “name1”
users[1] = “name2”
….

I have tried them to loop through for loop but without success.

like image 417
Dino.F Avatar asked Oct 26 '25 21:10

Dino.F


1 Answers

Are you looking for the map function?

var shareholders = ['name1', 'name2', 'name3'];
var users = shareholders.map(function (user){
  return user; // Do transformation here
});
console.log(users);
like image 186
Valentin Klinghammer Avatar answered Oct 28 '25 10:10

Valentin Klinghammer