The operation of JSON array in jquery

Source: Internet
Author: User

Link Address: http://blog.sina.com.cn/s/blog_86be5e2f0101bc3k.html


In the case of working with JSON arrays in jquery, the traversal is much more, but removing them with add does not seem to be too much.

Today tried Json[i].remove (), Json.remove (i) not after, look at the Web page of the DOM object as if the JSON data appears as an array, looked at the next relevant JS array of operation a try really cool.

Record them.

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

var arrayobj = new Array ([element0[, element1[, ... [, ELEMENTN]]]); Create an array and assign a value

To illustrate, although the second method creates an array that specifies the length, the array is actually variable in all cases, meaning that even if the length is 5, the element can still be stored outside the specified length, note that the length changes accordingly.

2. Access to elements of an array

var testgetarrvalue=arrayobj[1]; Gets the element value of the array

Arrayobj[1]= "This is the new value"; Assigning a new value to an array element

3. Adding array elements

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 "".

4. Deletion of array elements

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

5. Interception and merging of arrays

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

6, copy of the 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

7. Sorting of array elements

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

8. String of array elements

Arrayobj.join (separator); Returns a string that connects each element value of an array, separated by separator.

toLocaleString, toString, valueOf: Can be seen as a special use of joins, not commonly used


The operation of JSON array in jquery

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.