0

I have this variable:

var txt = { 
    'e3fe40': { 
        'name' : 'Menu2',
        'data': {
            'prompt_say' : 'Thank you for calling ',
            'keys[]' : ['1','2'],
            'choices[]' : [
                'start/e3fe40/d2d27',
                'start/e3fe40/77c197'
            ]...

While I can parse with no problems things such as txt[position].data.... , I cannot seem to be able to parse these two:

txt[position].data.keys and txt[position].data.choices

  (last two entries from code above)

I tried with

txt[position].data.keys[1], 
txt[position].data.keys[],
txt[position].data.keys

etc.

None worked. I always get "undefined" value.

Any ideas?

1 Answer 1

3
txt[position].data['keys[]']

The key keys[] is the name of the key. You can't arbitrarily insert JSON-like strings in as a key name and expect it to parse. This obviously assumes that the value of position is e3fe40 or whatever it needs to be.

Sign up to request clarification or add additional context in comments.

3 Comments

correct, position is "e3fe40" . So how would I go around and see that the "keys" key contains '1' and '2'?
The code I posted gets you the value of the keys[] element. It's an array that contains two elements... the strings 1 and 2. What were you expecting?
Nothing, i was just super tired and read through the lines :) I saw what you were saying after reading it for the second time. Thanks!

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.