2

Just for an example of what I am trying to do:

item1.item2
//item2 has four objects
//object0, object1, object2, object3
//each object has the same property within it 'propTitle'

I need to get the propTitle value of all 4 objects. What do I need to do to accomplish this?

1
  • item1.item2.object0.propTitle etc? Commented Mar 6, 2012 at 18:05

1 Answer 1

4
var titles = $.map(item1.item2, function(v, i) {
    return v.propTitle;
});

Or without jQuery, assuming item1.item2 is an Array...

var titles = item1.item2.map(function(v, i) {
    return v.propTitle;
});

Though you'll need a patch to support older browsers.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map#Compatibility

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.