jquery Arrays and dictionaries

Source: Internet
Author: User

1 Creation of arrays

var arrayobj = new Array (); Create an array

var arrayobj = new Array ([size]); Create an array and specify the length, note not the upper limit, is the length

2 loops for an array

$.each (Object,fucntion (Num,item) {
alert (num);//array subscript

alert (item);//array element value
}

3 array element manipulation

Arrayobj. Push ([Item1 [item2] [... [Itemn]]); /Adds one or more new elements to the end of the array and returns the new length of the array

Arrayobj.unshift ([Item1 [item2 [...] [Itemn]]); /Adds one or more new elements to the beginning of the array, the elements in the array are automatically moved back, returning the new length of the array

Arrayobj.splice (insertpos,0,[item1[, item2[, ... [, Itemn]]]); /inserts one or more new elements into the specified position of the array, the element at the insertion position automatically moves back, and returns "".

Arrayobj.pop (); Removes the last element and returns the element value

Arrayobj.shift (); Removes the first element and returns the element value, and the elements in the array are automatically moved forward

Arrayobj.splice (Deletepos,deletecount); Removes the specified number of DeleteCount elements from the specified position deletepos, returning the removed element as an array

Arrayobj.slice (start, [end]); Returns a portion of the array as an array, noting that the element of end is not included, and if the end is omitted, all elements after start are copied

Arrayobj.concat ([item1[, item2[, ... [, Itemn]]]); Concatenate multiple arrays (which can also be strings, or a mixture of arrays and strings) into an array, returning a new, well-connected array

Arrayobj.slice (0); Returns a copy array of the array, note that it is a new array, not a pointer to the

Arrayobj.concat (); Returns a copy array of the array, note that it is a new array, not a pointer to the

4 array sorting

Arrayobj.reverse (); Reverses the element (the top row to the last and last to the top), returning the array address

Arrayobj.sort (); Sort the array elements, returning the address of the arrays

JSON data traversal {' key ': ' Value '}

$.each (data, function (k, v) {

Alert (k); Key value

Alert (v); Value values

});

jquery Arrays and dictionaries

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.