attribute values into an array

attribute values into an array

Hi I'm new to jQuery but loving its power. Anyway, I'm interested in discussion of the following problem:

I have a collection of divs each with their own numerical id that i use for ordering. They look like something like this:

  1. <div class = "note" noteId = "1">...
  2. <div class = "note" noteId = "4">...
  3. <div class = "note" noteId ="23">...
  4. ...etc


I want to read the noteId values into a javascript array. I have found two successful ways of doing this but I arrived at these solutions by trial and error and I'm curious as to what the accepted way of doing this is.

Here are the successful methods I have used. Method 1 run seems to run marginally faster:

method 1
  1. arrayVariable =[ ];
  2. arrayVariable = $("note").map(function()
  3. {
          return $(this).attr("noteId");
    }) ;

method 2
  1. var arrayVariable = [ ];
  2. $("note").each(function (i)
  3. {
            arrayVariable[i]=$(this).attr("noteId");
    });


I'm not satisfied with either of these and am sure there must be a snappy way involving a jQuery function that returns an array of attribute values directly. Something like this, which DOES NOT WORK
  1. var arrayVariable =  [ ];
  2. arrayVariable = $.makeArray($("note"]).attr("noteId"));
This just returns an empty array. If there isn't a standard way of doing this then which of the two working methods strikes you as the most satisfactory way to achieve this. Thanks for your time.