Home > Web Front-end > JS Tutorial > body text

json data processing skills (fields with spaces, adding fields, sorting, etc.)_javascript skills

WBOY
Release: 2016-05-16 17:32:18
Original
1530 people have browsed it

1. The normal value of json data: json[i].fieldName

2. The field of json data has spaces: eval('json[' i ']["' field '"]')

3. Assignment of json data: eval('json[' i ']["' field '"]=' jsonFilter.length);

4. Add fields to json data: loop all data , just json[i].newField=defaultValue

5. Sorting of json data: equivalent to sorting of arrays, json.sort(function (a, b) { return a[name] > b [name] ? 1 : -1 });

6. Copy of json data: var newObject = jQuery.extend(true, {}, oldObject); Please refer to: Copy of json object in jQuery (array and objects)

7. Adding and deleting json arrays, etc.: concat method | join method | pop method | push method | reverse method | shift method | slice method | sort method | splice method | toLocaleString method | toString method | unshift method | valueOf method

8. Example of creating a json array: var jsonArr=[]; var item={id:'id1',value:'val1'}; jsonArr.push(item); This creates a json array with two fields id and value, and adds a record to the array.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!