0

I'm trying to get at the values in objects that are within an array, that is the value of an object in an array.

jQuery

// aim:  to alert value of 'm1' for each object (represented as a day)

myArray = [{"monday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"tuesday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"wednesday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"thursday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"friday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"saturday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]},{"sunday":[{"m1":"val1"},{"s1":"val2"},{"m2":"val3"},{"s2":"val4"},{"m3":"val5"},{"s3":"val6"}]}]

$.each(myArray, function(k,v) {
  $.each(k, function(k2,v2) {
      alert(v2.m1)
});
});

jsFiddle

http://jsfiddle.net/rwone/py8Jz/3/

0

1 Answer 1

1

Try this: http://jsfiddle.net/merrifield69/py8Jz/5/

$.each(myArray, function (k, v) {
    $.each(v, function (k2, v2) {
        alert(v2[0].m1)
    });
});

If you just take a second to think about where you are in each loop it's pretty easy to figure out. :]

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.