Reading the d3 book from O'Reilly, I learned something important today.
This was the difference between objects and arrays.
Arrays have square brackets and are referred to with numbers.
For example
var number = [5,10,15,20,25];
numbers[0] // returns 5
numbers[4] // returns 25
In contrast
Objects
Well it seems that almost anything can be a JavaScript object but...
Described in curly brackets "{"
Example:
var fruit = { kind:"grape", color:"red", quantity:12, tasty=true};
to reference this use the dot notation
fruit.kind // returns "grape"
fruit.color // returns "red"
You can have arrays of objects or objects of arrays etc....
In my rendering of CD40 in JSON, I had an array of objects.
IN that case I ended up with
fruits[0].quantity
type of notation.
It's possible to render this in an array of arrays too.
Will work just as well :-)
To describe the positions, use numbers.
This should/might make life easier.
No comments:
Post a Comment