Home Web Front-end JS Tutorial Example of deep assignment to a json array using javascript_javascript skills

Example of deep assignment to a json array using javascript_javascript skills

May 16, 2016 pm 04:41 PM
json array Assignment

<!DOCTYPE HTML> 
<html> 
<head> 
<title>test1</title> 
</head> 
<body> 
<script> 
var arr={ 
"name":"zhansan", 
"age":23, 
"address":{ 
"city":"beijing", 
"gas":{ 
"gasSheet":"气态流出物月报", 
"H_adjust":1 
}, 
"time":{ 
"duration":31 
} 
}, 
"units":{"title":"function"} 
} 
function show(obj){ 
var tmp={}; 
for(var i in obj){ 
if(obj[i]=="object"){ 
<span style="color:#ff0000;">tmp[i]=show(obj[i]);</span> 
} 
else{ 
<span style="color:#ff0000;">tmp[i]=obj[i]</span> 
} 
} 
return tmp; 
} 

var result=show(arr); 
console.log(result); 

</script> 
</body> 
</html>
Copy after login

利用递归思想,其中注意赋值语句

可用于不同的环境

Copy after login
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

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)

How to enable copy and paste for VMware virtual machines How to enable copy and paste for VMware virtual machines Feb 21, 2024 am 10:09 AM

You can easily copy and paste text and files between VMware virtual machines (VMs) and physical systems. This capability allows you to easily transfer images, formatted and unformatted text, and even email attachments between virtual machines and host systems. This article will show you how to enable this feature and demonstrate methods for copying data, files, and folders. How to Enable Copy/Paste in VMware VMware provides three different ways to copy data, files or folders from a virtual machine to a physical computer and vice versa, as explained below: Copy and Paste Elements Drag and Drop Feature Folder Sharing 1 ] Enable copy-paste using VMware Tools You can use the keyboard if your VMWare installation and guest operating system meet the requirements

How to copy a page in Word How to copy a page in Word Feb 20, 2024 am 10:09 AM

Want to copy a page in Microsoft Word and keep the formatting intact? This is a smart idea because duplicating pages in Word can be a useful time-saving technique when you want to create multiple copies of a specific document layout or format. This guide will walk you through the step-by-step process of copying pages in Word, whether you are creating a template or copying a specific page in a document. These simple instructions are designed to help you easily recreate your page without having to start from scratch. Why copy pages in Microsoft Word? There are several reasons why copying pages in Word is very beneficial: When you have a document with a specific layout or format that you want to copy. Unlike recreating the entire page from scratch

Detailed explanation of sorting and filtering operations of JSON arrays in Java. Detailed explanation of sorting and filtering operations of JSON arrays in Java. Sep 06, 2023 pm 03:22 PM

Detailed explanation of sorting and filtering operations of JSON arrays in Java In Java development, processing JSON data is a common task. As one of the commonly used data structures, JSON array often requires sorting and filtering operations in practical applications. This article will introduce in detail the sorting and filtering operations of JSON arrays in Java and provide corresponding code examples. 1. Sorting operation of JSON array: Use JSONArray object to store JSON array in Java, and use json library to process JSON data

Get started quickly: JSON array merging and splitting techniques in Java. Get started quickly: JSON array merging and splitting techniques in Java. Sep 06, 2023 am 10:21 AM

Get started quickly: JSON array merging and splitting techniques in Java In modern software development, data format and transmission have become increasingly important. Among them, JSON (JavaScriptObjectNotation) is a commonly used data format, especially suitable for front-end and back-end interaction and data storage. In Java development, we often need to deal with JSON objects and JSON arrays. This article explains how to merge and split JSON arrays in Java, along with tips and examples for implementing these operations.

Unlock macOS clipboard history, efficient copy and paste techniques Unlock macOS clipboard history, efficient copy and paste techniques Feb 19, 2024 pm 01:18 PM

On Mac, it's common to need to copy and paste content between different documents. The macOS clipboard only retains the last copied item, which limits our work efficiency. Fortunately, there are some third-party applications that can help us view and manage our clipboard history easily. How to View Clipboard Contents in Finder There is a built-in clipboard viewer in Finder, allowing you to view the contents of the current clipboard at any time to avoid pasting errors. The operation is very simple: open the Finder, click the Edit menu, and then select Show Clipboard. Although the function of viewing the contents of the clipboard in the Finder is small, there are a few points to note: the clipboard viewer in the Finder can only display the contents and cannot edit them. If you copied

How to convert JSON array to CSV in Java? How to convert JSON array to CSV in Java? Aug 21, 2023 pm 08:27 PM

JSON can be used as a data exchange format, it is lightweight and language independent. A JSONArray can parse text strings to produce vector-like objects and supports the java.util.List interface. We can convert JSON array to CSV format using org.json.CDL class, which provides a static method toString() for converting JSONArray to comma-separated text. We need to import the org.apache.commons.io.FileUtils package to store data in a CSV file using the writeStringToFile() method. Syntaxpublicstaticj

Disable or enable automatic copy selection for copying in Terminal Disable or enable automatic copy selection for copying in Terminal Mar 24, 2024 am 09:46 AM

This article will show you how to enable or disable automatic copying of selections to the clipboard in Windows Terminal. Windows Terminal is a multi-tab terminal emulator developed by Microsoft specifically for Windows 11/10, replacing the traditional command prompt. It supports running applications such as Command Prompt, PowerShell, WSL, Azure, etc. Often when working in the terminal, users need to copy commands and output, however the terminal does not support copying selection operations by default. Keep reading this article to learn how to fix this issue. How to enable or disable automatic copying of selections to cache in Terminal? Here's how you can enable or disable automatic copying of selections to the Terminal clipboard: Open the Terminal application and click above

How can we merge two JSON arrays in Java? How can we merge two JSON arrays in Java? Aug 20, 2023 pm 11:05 PM

A JSON is a lightweight data exchange format, and the format of JSON is a key-value pair. JSONArray can parse text from a string to generate a vector-like object and supports the java.util.List interface. We can merge two JSON arrays in Java using org.json.simple.JSONArray class. We can merge two JSON arrays in the following program using the addAll() method (inherited from interface java.util.List). Example

See all articles