View Full Version : How do I print an Array of Objects?

03-08-2012, 02:39 PM

I have a pretty straight forward question dealing with JQuery/Javascript (I'm pretty new to both, so the syntax is still escaping me). I have a javascript file that holds an array of objects inside of it (addresses to be exact) and I then need to take that array and call it to print into the Title attribute of a <li> after the list has been populated.

Below is the Javascript arrray:

var banner_data = [ "address1","address2","address3","address4"];
var obj = { one:"address1", two:"address2", three:"address3", four:"address4" }

And this is how it is being called in the HTML:

var $this = $(this); // current list item
var idx = $this.index();
var thisAddress = banner_data[idx];
$this.attr('title', thisAddress.append[4])

any thoughts? I have jQuery 1.7.1 installed, a fully valid html/css and a proper doctype (just to cover our bases haha)

03-08-2012, 02:41 PM
also, It does target the correct title in the correct lists. When I change

$this.attr('title', thisAddress.append[4])


$this.attr('title', 'test')

it will change the title attribute to 'test' perfectly. I'm just having trouble with the append/print syntax

03-08-2012, 04:49 PM

$this.attr('title', thisAddress.append[4])


$this.attr('title', thisAddress)

fixed it