JQuery: utility functions VII – concatenating arrays

Published Mon, Aug 10 2009 11:23

In this post we’re going to take a look at the merge utility function. This function expects two arrays that will be merged. The method returns a reference to the first array augmented with the elements contained on the second (which remains unchanged). Here’s a small snippet that shows how to use this function:

var arr = [0, 1, 2];
var anotherArr = [-1, -2, -3];
var merged = $.merge(arr, anotherArr);

The important thing here is that you shouldn’t forget that merged points to arr and that arr now has the items contained by anotherArr. Notice also that this function doesn’t remove duplicates. If you need that you’ll need to use the $.unique method (though it only works with DOM nodes). Keep tuned for more on JQuery.

Filed under:

Comments

# 9eFish said on Monday, August 10, 2009 11:21 AM

9efish.感谢你的文章 - Trackback from 9eFish

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above:  

Search

This Blog

Tags

Community

Archives

Syndication

Email Notifications

News




  • View Luis Abreu's profile on LinkedIn


    Follow me at Twitter

    My books

    Silverlight 4.0: Curso Completo

    ASP.NET 4.0: Curso Completo

    Portuguese LINQ book cover

    Portuguese ASP.NET 3.5 book cover

    Portuguese ASP.NET AJAX book cover

    Portuguese ASP.NET AJAX book cover