Question: I have a bunch of elements that I wish to convert to an array of attributes and I'm using the following code:

```
var attributes = [];
$("#id").find("tag").each(function() {
    attributes.push($(this).attr("attribute"));
});

```

Is there a neater way to do this? Feels like I'm using shears to trim my finger nails.

I've been using `d3` recently, it feels like there could be a way to do this in a way that would look like `var attributes = $("#id").find("tag").attr("attribute");` but this just sets the variable to the attribute of the first element in the selection.

Answer: 
You can use [`.map()`](http://api.jquery.com/map/) along with `.get()`

> 
> Pass each element in the current matched set through a function, producing a new jQuery object containing the return values.
> 
> 
> 

```
var attributes = $("#id tag").map(function() {
    return $(this).attr("attribute");
}).get();

```
Use `map()` method like following.

```
var attributes = $("#id tag").map(function () {
    return $(this).attr("attribute");
}).get();

```