jquery's operations on data and objects

Source: Internet
Author: User

<script type= "Text/javascript" src= "Jquery-1.8.2.min.js" ></script>

<script type= "Text/javascript" >
$ (function () {
var arr={"Zhang San": 80, "John Doe": 78, "Zhao Wu": 85};
var str= "<li class= ' title ' > Name: Score </li>";
$.each (Arr,function (index,value) {//traversal array
str+= "<li>" +index+ ":" +value+ "</li>";
})
$.each ($.ajaxsettings,function (property,value) {//Traversal object
str+= "<li>" +property+ ":" +value+ "</li>";
})
$ ("ul"). Append (str);
Data filtering
var strtmp= "Pre-screening data:";
var arrnum=[4,6,2,5,10,13,1,30];
var arrget=$.grep (arrnum,function (ele,index) {//Tool function, $.grep () function filters any element in the array
return ele<10 && index<4
})
Change the elements in an array
var arrmap=$.map (arrnum,function (ele,index) {//Tool function, $.map () function changes the elements in the array
if (ele<10 && index< 4)
return ele+1;
})
Strtmp+=arrnum.join ();
strtmp+= "<br></br> filtered data:";
Strtmp+=arrget.join ();
Strtmp+=arrmap.join ();
$ ("#divTip"). Append (strtmp);

Search for the position of the specified element in the array
var arrinarray=$.inarray (10,arrnum); The $.inarray () function searches the position of the specified element in the array
strinarray= "Search results:";
Strinarray+=arrinarray;
$ ("#divTip"). Append (Strinarray);
})
</script>
<body>
<ul></ul>
<div id= "Divtip" ></div>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.