enter image description here
How do I get the value of BrandID?
asked Dec 27, 2013 at 7:28
titi
1,0355 gold badges16 silver badges31 bronze badges
-
Is this about getting a property, or about looping over all properties?bjb568– bjb5682013年12月27日 07:29:53 +00:00Commented Dec 27, 2013 at 7:29
-
Getting a property value.titi– titi2013年12月27日 07:31:11 +00:00Commented Dec 27, 2013 at 7:31
-
1How about showing us what you've tried?monners– monners2013年12月27日 07:31:47 +00:00Commented Dec 27, 2013 at 7:31
-
1Try data[0].Item.BrandIDRingo– Ringo2013年12月27日 07:33:24 +00:00Commented Dec 27, 2013 at 7:33
-
1I down-voted for the level of lazy. This is something you could have easily found through a google search.monners– monners2013年12月27日 07:34:38 +00:00Commented Dec 27, 2013 at 7:34
4 Answers 4
Use this yourObjectArray[0].Item.BrandID
answered Dec 27, 2013 at 7:31
Ravindra Gullapalli
9,1983 gold badges51 silver badges73 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Ringo
yourObjectArray[0].Item.BrandID I think.
For your example:
objRef[0]["Item"]["BrandID"]
or you can use:
objRef[0].Item.BrandID
For Iterating in your array you will use:
var i;
for(i=0; i < objRef.Length ; i++)
{
var brandId = objRef[i].Item.BrandID;
// or
var brandId = objRef[i]["Item"]["BrandID"];
// your code blocks to process blockId
}
answered Dec 27, 2013 at 7:33
Khurram Hassan
1,5541 gold badge13 silver badges21 bronze badges
5 Comments
bjb568
Why do it in bracket notation?
Khurram Hassan
It is just an example. You can use it in either way. Using Bracket notation helps in some cases.
bjb568
Example or not, it's not where you'd use it.
bjb568
Those cases being when the key name is unknown.
Khurram Hassan
Correct. When key name is unknown or changes dynamically.
Go with this ..
ObjectArray[0].Item.BrandID
answered Dec 27, 2013 at 7:34
Tony Jose
1,6641 gold badge13 silver badges26 bronze badges
Comments
You mean this?
for(var i = 0, len = yourObjectArray.length; i < len; i++) {
var youNeed = yourObjectArray[i].Item.BrandID;
}
Comments
lang-js