Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Retrieving array values within a profile


Level 5


I'm attempting to retrieve specific values from an array I have stored within a profile.  The usual method I would use to retrieve these via Javascript doesn't appear to be working, so not sure if I've missed something obvious or not?!

I have created an array with 2 dimensions, which, from looking at the mbox trace, seems to look as I would expect it to look, see below:


The above array contains 4 2 dimensional values.  If I copy this local profile to a variable, e.g.

var testArray = [];

var testArray = user.getLocal('Debug_AA.Init_2');

..and apply the '.length' i.e. testArray.length, it returns 4, which I would expect.  I have also been able to push values to this, again, verifying for me this is an array.

When I attempt to retrieve a value from this, e.g. testArray[0][0], like I would normally do, it doesn't work, when I save the profile I get the following. 


Maybe there's a specific way in which to get these values within the profiles which is different from regular javascript?! I'd be grateful for any help.

Many thanks


5 Replies


Community Advisor

Hi Dan,

Could you attach the full script?


Level 5

Hi Andrey

I've included the beginning of the script, see below.  To summarise, I'm retrieving the contents of local profile 'Product_Affinity' and putting this in the variable 'product_affinity' if it exists.  I'm then attempting to put the value located in index [0][0] of this 2 dimension array into the variable 'array_pick'.  This is the line that creates the error.

// *** Profile Script beginning

var product_affinity = [];

var prod_display_index;

var prod_display;

var prod_type_pos;

var add_prod;

var add_prod_value;

var prod_affinity_val;

var prod_type;

var pts=[];

var new_session;

var i;

//var push_array;

if (user.getLocal('Product_Affinity')) {

user.setLocal('Debug_AA.Init_1','prod_aff from profile: ' + user.getLocal('Product_Affinity')); // for purposes of debugging

product_affinity = user.getLocal('Product_Affinity'); //

//user.setLocal('Debug_AA.Init_2','prod_aff from var: ' + product_affinity); // for purposes of debugging

}else if (!user.getLocal('Product_Affinity')) {

user.setLocal('Debug_AA.Init_2','Profile doesnt exist'); // for purposes of debugging


user.setLocal('Debug_AA.Init_3', product_affinity); // for purposes of debugging to prove product_affinity exists

// *** Populate product_affinity var array, used for testing purposes only

//var push_array = new Array(99, 5);



  // user.setLocal('Debug_AA.Init_5: prod affinity push', product_affinity); // for purposes of debugging to prove product_affinity exists at this point

// get array value

var array_pick;

array_pick = product_affinity[0][0]; // this line breaks the script, commenting this out allows script to run!


// *** Profile Script ends

Many thanks



Community Advisor


Add if ( product_affinity && product_affinity[0] && product_affinity[0][0] ) before array_pick = product_affinity[0][0];

This will help prevent a JS error if the array element does not exist.

Let me know if that solves the issue.


Level 5

Hi Andrey

Unfortunately this doesn't solve it, for some reason when I try to use those 2 index positions in the product_affinity variable, e.g. product_affinity[x][y] the code errors.  I don't know whether the javascript within the profiles is capable of taking 2 dimensions, seems odd I'm able to count the number and push, but seem unable to retrieve these individual values within it.




Community Advisor

Hi Dan,

It seems to me there may be something with the code logic rather than with the limited support of multi-dimensional arrays... If you are sure in the code logic, try to replace the array with an object.