A Little Known List of JavaScript Functions Equivalent to PHP Functions in jQuery

Many of us PHP developers often find working with JavaScript arrays to be a frustrating task. PHP has a number of very powerful built in functions like: in_array(), is_array(), array_merge(), array_map(), and array_unique() that are just plain missing in JavaScript. Over the years, many of these functions have been ported into JavaScript buy developers much like us. In fact, I recently did a port partial port of the PHP strip_tags() function to JavaScript. (Note: There is a popular library of PHP->JS functions called PHP.JS you can check out for functions not included in this example or if you are not using jQuery.)

Until now, developers working with arrays in JavaScript were either forced to obtain the data returned from these functions on their own or spend a great deal of time searching the net for a solution that actually works. Thankfully, the jQuery developers have written a number of these functions into the core jQuery library but for some reason not many developers, even those using jQuery don’t know they are there to use!

jQuery / JavaScript PHP Equivalent Array Functions

PHP in_array() Equivalent in JavaScript

jQuery.inArray(value,array)

PHP is_array() Equivalent in JavaScript

jQuery.isArray(array)

PHP array_map() Equivalent in JavaScript

jQuery.map(array,callback)


PHP array_merge() Equivalent in JavaScript

jQuery.merge(array1,array2)

PHP array_unique () Equivalent in JavaScript

jQuery.unique(array)

Other jQuery / JavaScript Array and Object Functions

In addition to these functions there are some other handy functions available to jQuery developers that work with Arrays and Objects. These include:

PHP get_object_vars() Equivalent in JavaScript

jQuery.makeArray(object)

Grep Style Search Function

jQuery.grep(array,callback,invert)

Object Extension

jQuery.extend(deep,target,object1,objectN)

Iterator Function

jQuery.each (object,callback)

(Note: None of these functions will work without the jQuery library. jQuery is a free, open source JavaScript library check out: http://jquery.com/ for more information.)

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)