Home > Article > Web Front-end > json data processing skills (fields with spaces, adding fields, sorting, etc.)_javascript skills
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.