0

I'm trying to load a two dimensional array from PHP, now I want to access each position of the array, to add it to an HTML element.

My actual code:

<script>
    $(document).ready(function() {
        var stores = <?php echo json_encode($stores); ?>;
        console.log(stores[2][0])
    });
</script>

Sadly the console returns "undefined".

How could I access for example only the id of the second store?

1
  • 1
    What about console.log( stores[2]['id'] );? Commented Jul 22, 2015 at 8:04

1 Answer 1

1

You can access id property of the second array element that way:

console.log( stores[2].id );

or

console.log( stores[2]['id'] );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.