0

This is my script, which I manged to put together using code on this link : Setting up a variable length two-dimensional array

stringWithSeper = "Panther^Pink,Green,Yellow|Dog^Hot,Top";
var blocks = stringWithSeper.split("|");
for (var i = 0; i < blocks.length; i++) {
    temp = blocks[i].split("^");
    result[temp[0]] = temp[1].split(",");
}

I'm confused. What's the structure of "result" ? Is it

result = {"Panther":{"Pink","Green","Yellow"}, "Dog":{"Hot","Top"}}

If not, what is it? I've been breaking my head over this for the past 3 days.

1 Answer 1

1

Here is your answer: alert(JSON.stringify(result))

Result: {"Panther":["Pink","Green","Yellow"],"Dog":["Hot","Top"]}

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

2 Comments

1)ok,how do I access the string "pink" within "panther" ? 2) How do I add "red" to the object so that it is {"Panther":["Pink","Green","Yellow","Red"],"Dog":["Hot","Top"]} using a function ?
1) result["Panther"][0] or result.Panther[0] . 2) result["Panther"].push("Red") . Basically each result["something"] is an array of strings. Therefore you can use this reference on how to use arrays: developer.mozilla.org/en/JavaScript/Reference/Global_Objects/…

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.