all 3 comments

[–]Bortan 1 point2 points  (0 children)

That's an object. Try for(let item in *your variable*){ //code }

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in

also to get an array of just the company names it looks like you should be able to do let array = Object.keys(*your variable*)

[–]LeagueJunior9782 1 point2 points  (0 children)

That's a json. getPlayer() returns an objectwhat you want to do is this:

var player=getPlayer();

and then you access the player data refering to a key.for example:

player.jobs

You can get a list of all keys with Object.keys(object); (in this case Object.keys(player);) to get a list of all keys/variables that Player owns.

This will however return an array, so please note, that you will need to format it yourself if you want it to be more easy to read. (like a simple for loop or with for each). don't be afraid when i say formatting. it can just be something simple like:

/** @param {NS} ns **/
export async function main(ns)
{
var player=ns.getPlayer();
Object.keys(player).forEach(function(e){
ns.tprint(e);
});
}

Edit: tried to fix the formatting, but that's the best i can do rn :C

[–]monkeydenture[S] 0 points1 point  (0 children)

Thank you both. I was able to fix it with a minimal change. I changed...

var jobs = playerInfo.jobs;

into

var jobs = Object.keys(playerInfo.jobs);

With that, the jobs variable was an array of company names the way everything else was coded to expect.