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

Basic operations of JavaScript arrays and objects

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the basic operation of JavaScript array and object". In the daily operation, I believe that many people have doubts about the basic operation of JavaScript array and object. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "basic operation of JavaScript array and object". Next, please follow the editor to study!

(1) creation of objects:

Var arr1 = {name: "Little Dragon", age: "21"}

(2) traverse the properties of the object:

$.each (arr1, function (I, j) {alert ("arr1 [" + I + "] =" + j);})

(3) object merging to eliminate duplicate elements (the same attribute of the latter overrides the previous attribute and is used for the object):

Extend (arr1, arr2)

Merge that is not culled (for arrays):

$.each ($.merge (arr3, arr4), function (I, j) {alert ("after merger [" + I + "] =" + j);})

(4) take out the corresponding data in the array according to the conditions:

$.each ($.grep (arr3, function (I, j) {/ / conditional take out return I < 5 match / return less than 5}), function (I, j) {alert ("result after fetching array: [" + I + "] =" + j);})

Returns more than five:

$.each ($.GREP (arr3, function (I, j) {return I < 5 function / although less than the sign}, true), / / set the reverse function (I, j) {alert ("result after fetching the array: [" + I + "] =" + j);})

(5) map the array:

Arr4 = $.map (arr3, function (I) {return I + 10 role / each element in the array + 10})

(6) check to see if there is a value in the array:

Alert (jQuery.inArray (100,100, arr3) =-1? "does not contain 100": "contains 100")

(7) convert the tags in html to an array:

$.each ($("p") .toArray (), function (I) {alert ("p [" + I + "] =" + $("# p" + I) .html ());})

(8) json data parsing:

Var obj = jQuery.parseJSON ("{\" name\ ":\" KwooShung\ ",\" age\ ":\" 21\ "}"); alert ("get the JSON method [obj.name] result:" + obj.name + "\ n\ nget the JSON method [obj.age] result is:" + obj.age);}); at this point, the study of "basic operation of JavaScript arrays and objects" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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