20 Useful jQuery Methods Part -3

20 Useful jQuery Methods Part -3

11. isArray()
Determine whether the argument is an array.
$.isArray() returns a Boolean indicating whether the object is a JavaScript array (not an array-like object, such as a jQuery object).

Finds out if the parameter is an array.

12 makeArray()
Convert an array-like object into a true JavaScript array.

When you create a collection of DOM elements with jQuery, you’re returned a jQuery object; in some situations, you might prefer that this be an array or regular DOM elements; the makeArray() function can do just that.

13. map()

Translate all items in an array or object to new array of items.

The map() method is remotely similar to grep(). As you might expect, it takes one parameter, a function. That function can have two parameters: the index of the current element and the element itself. Here’s what happens: the function that you pass in will be run once for each item in the collection; whatever value is returned from that function takes the place of the item it was run for in the collection.

14 parseJSON()
Takes a well-formed JSON string and returns the resulting JavaScript value.

If you’re using $.post or $.get—and in other situations that you work with JSON strings—you’ll find the parseJSON function useful. It’s nice that this function uses the browsers built-in JSON parser if it has one (which will obviously be faster).

15. proxy()

Takes a function and returns a new one that will always have a particular context.

This method is most useful for attaching event handlers to an element where the context is pointing back to a different object. Additionally, jQuery makes sure that even if you bind the function returned from jQuery.proxy() it will still unbind the correct function if passed the original.

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *