First off, it's important to note that this is not an array, it's an object definition.
An array can be defined as:
[
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAJYCAYAAACadoJwAAAgAElEQ…ACCCCAAAIIIICAvwIEIP760zoCCCCAAAIIIIAAAoES+P992sgQ2E6rdwAAAABJRU5ErkJggg==",
"splash.png",
1024,
768,
1969,
1477,
800,
600,
-585,
-406
]
Which is doesn't the keys, like "data":
(which can also be expressed as data:
) It seems you definitely want to access values by key, so what you really want is:
var data, name, myObject;
// NOTE: We do not "quote" object keys under normal circumstances.
myObject = {
data:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAJYCAYAAACadoJwAAAgAElEQ…ACCCCAAAIIIICAvwIEIP760zoCCCCAAAIIIIAAAoES+P992sgQ2E6rdwAAAABJRU5ErkJggg==",
name:"splash.png",
imageOriginalWidth:1024,
imageOriginalHeight:768,
imageWidth:1969,
imageHeight:1477,
width:800,
height:600,
left:-585,
top:-406
}
data = myObject["data"]; // We don't usuaully use this
name = myObject["name"]; // style, although it works.
//
// It's generally reserved for
// dynamic access.
//
// i.e. we make a string to match the keyname.
However, to be correct you should use dot syntax to access the object key.
data = myObject.data;
name = myObject.name;
I hope this has cleared things up a little for you.
On a side note DO NOT use names like $array
. First don't use the $
prefix for normal variables, this isn't PHP or BASIC.
Secondly, when you have an object, you want it to be named something that is useful / meaningful / memorable. (naming things is hard!)
When you name things properly, other people can read and understand your code, and after a heavy weekend on the town, so can you.