Home  >  Article  >  Web Front-end  >  Can jquery use functions on arrays?

Can jquery use functions on arrays?

WBOY
WBOYOriginal
2022-09-07 17:09:561263browse

jquery can use functions on arrays; an array is a collection of certain types of data. The data type can be an integer, a string, or even an object. jquery can use functions such as trim, grep, inArray, unique, etc. to operate array.

Can jquery use functions on arrays?

The operating environment of this article: Windows 10 system, jquery version 3.6.0, Dell G3 computer.

jquery can use functions on arrays

jquery array processing functions are organized as follows:

1, $.trim(value)

Remove any leading or trailing whitespace characters from value

2, $.each(container, callback(key,value))

For each element of the container The items are iterated over, calling the callback function callback for each item.

container can be an object or an array. If it is a js object, each of its properties is iterated; if it is an array, each of its elements is iterated.

3. $.extend(target, source1, source2, ..., sourcen)

Use the properties of the source1...n object to extend the target object. The return value is the expanded object.

4.$.getScript(url, callback)

Dynamic loading of js scripts. And call the callback function when the script is successfully fetched.

5.$.noConflict

Avoid $alias conflict. Once the $.noConflict function is executed, it must be called with the jQuery name.

6. $.grep(array, callback, invert)

Traverse the passed array and call the swap function for each element. The return value of the callback function determines whether to collect the current elements into a new array, and the new array is used as the return value of $.grep. The callback function needs to return a bool type value. If invert is omitted or false, elements for which the callback function returns TRUE are collected into the return result. If invert is true, the elements whose callback function returns false are collected into the return result.

7.$.map(array,[callback])

The conversion function will be called for each array element, and will pass a value representing the The converted element is taken as an argument. The conversion function can return the converted value, null (removes the item in the array), or an array containing the value expanded into the original array.

8、$.inArray(val,array)

Determine whether the value exists in the array, counting from 0 (if not found, return -1)

9.$.merge(first,second)

Merge two arrays. The returned result modifies the contents of the first array - the elements of the first array are followed by the elements of the second array. This method uses jQuery's method to replace the native concat() method, but its function is not as powerful as concat(), which can merge multiple arrays at the same time.

10, $.unique(array)

Filter duplicate elements in the array and delete duplicate elements in the array. Only delete DOM element arrays, not strings Or numeric array

11, $.makeArray(obj)

Convert the array-like object to an array object. The array-like object has a length attribute, and its member index is 0 to length-1.

12. $(dom).toArray()

Restore all DOM elements in the jQuery collection into an array. It is not a commonly used method. I personally think it is as redundant as $.makeArray.

Recommended related tutorials: jQuery video tutorial

The above is the detailed content of Can jquery use functions on arrays?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Does vue include jQuery?Next article:Does vue include jQuery?