Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is there a map method in jquery?

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "is there any map method in jquery?". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

There is a map method in jquery; this method is used to handle each attribute of each element or object in the array using the specified function, and the result is encapsulated as a new array return with the syntax of "$.map (array or object to be processed, specified handler)" or "jquery object .map (specified handler)".

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

Is there a map method in jquery?

The $.map () function is used to process each element in the array (or each attribute of the object) using the specified function and to encapsulate the result as a new array return.

1. Prior to jQuery 1.6, this function only supported traversing arrays; since 1.6, it also supports traversing objects.

2. Map () also passes in two parameters to the function: one is the element or attribute value of the current iteration, and the other is the array index or object property name of the current iteration item.

3. The function returns a value as an element in the result array, and if the return value is null or undefined, it will not be added to the result array.

Grammar

$.map (object, callback)

The array or object that needs to be processed specified by the object Array/Object type.

Handler specified by callback Function type

There are two forms:

$.map (arr | obj,callback): converts elements from one array to another. Callback:function (ele,i): ele is the currently processed element, I is the subscript of the currently processed element, and returns the JavaScript native array.

Jquery object .map (callback): converts a set of elements to another array, returning an jquery array object. Callback:function (iQuery Ele): note that the location of format one is different.

Examples are as follows:

123div {color:blue;} p {color:green; margin:0;} span {color:red;}

(function () {var arr = ["a", "b", "c", "d", "e"]; $("div") .text (arr.join (",")); arr = $.map (arr, function (n, I) {return (n.toUpperCase () + I);}); $("p") .text (arr.join (",")); arr = $.map (arr, function (a) {return a + a;})) $("span") .text (arr.join (",");})

Output result:

This is the end of the content of "is there any map method in jquery"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report