Home Web Front-end JS Tutorial json data processing skills (fields with spaces, adding fields, sorting, etc.)_javascript skills

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

May 16, 2016 pm 05:32 PM
json Add field space

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.

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Combination of golang WebSocket and JSON: realizing data transmission and parsing Combination of golang WebSocket and JSON: realizing data transmission and parsing Dec 17, 2023 pm 03:06 PM

Combination of golang WebSocket and JSON: realizing data transmission and parsing

What is the difference between MySQL5.7 and MySQL8.0? What is the difference between MySQL5.7 and MySQL8.0? Feb 19, 2024 am 11:21 AM

What is the difference between MySQL5.7 and MySQL8.0?

Performance optimization tips for converting PHP arrays to JSON Performance optimization tips for converting PHP arrays to JSON May 04, 2024 pm 06:15 PM

Performance optimization tips for converting PHP arrays to JSON

The difference between full-width spaces and half-width spaces The difference between full-width spaces and half-width spaces Mar 25, 2024 pm 12:45 PM

The difference between full-width spaces and half-width spaces

Pandas usage tutorial: Quick start for reading JSON files Pandas usage tutorial: Quick start for reading JSON files Jan 13, 2024 am 10:15 AM

Pandas usage tutorial: Quick start for reading JSON files

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string Nov 18, 2023 pm 01:59 PM

Use the json.MarshalIndent function in golang to convert the structure into a formatted JSON string

How do annotations in the Jackson library control JSON serialization and deserialization? How do annotations in the Jackson library control JSON serialization and deserialization? May 06, 2024 pm 10:09 PM

How do annotations in the Jackson library control JSON serialization and deserialization?

How to handle XML and JSON data formats in C# development How to handle XML and JSON data formats in C# development Oct 09, 2023 pm 06:15 PM

How to handle XML and JSON data formats in C# development

See all articles