0

How can I make php array into Javascript object code?.

2

1 Answer 1

0

You can try this. This is how you dynamically name object properties and object values. I am assuming you want to build this dynamically where the property names are coming from a source. All you have to do is loop through the values

var treeData = {};
Loop Here
var nameProperty = "propertyName";
var nameValue = "propertyValue";
var childProperty = "child";
var childValue = {};

Try This.

http://jsfiddle.net/zKdMa/1/

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

1 Comment

Thanks. This helped a lot. But I am still having a problem with the loop. How do I keep the hierarchical structure as shown in the original question. Do I increment 1++ every iteration. I am a bit confused? Can You Help? I would appreciate it:)

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.