I'm encountering an issue while attempting to use a variable for accessing an array value resulting in an undefined error.
var ordernum = 54;
keys[ordernum][ "keys" ];
Uncaught TypeError: Cannot read property 'keys' of undefined
When I try keys["54"][ "keys" ];
it works perfectly. However, due to being within a for
loop, I need to utilize the variable.
Is there a way for me to achieve the same result using the variable?
Snippet from the complete code:
var customers = <?php if ( isset($customers) ) { echo json_encode($customers); } ?>;
var keys = <?php if ( isset($keystable) ) { echo json_encode($keystable); } ?>;
for ( var i = 0; i < customers.length; i++ ) {
var ordernum = customers[ i ][ "order" ];
table += '<tr bgcolor="#ffffff">';
table += '<td>' + customers[ i ][ "email" ] + '</td>';
table += '<td>' + customers[ i ][ "org" ] + '</td>';
table += '<td style="width:450px;">' + customers[ i ][ "notes" ] + '</td>';
table += '<td>' + keys[ordernum.toString()][ "keys" ] + '</td>';
table += '</tr>';
}