demo2:
Home Web Front-end JS Tutorial js handles common operations such as json and string comparison_javascript skills

js handles common operations such as json and string comparison_javascript skills

May 16, 2016 pm 05:23 PM
String comparison

js handles common operations such as insertion, modification, deletion of json format, and comparison of strings

demo 1:
Insertion and deletion of json format

Copy code The code is as follows:

















Running result:
js handles common operations such as json and string comparison_javascript skills
demo2:
Copy code The code is as follows:










< ;input type="button" value=">" onclick="toRight();submit()"/>











Run results:
js handles common operations such as json and string comparison_javascript skills
Demo 3:

Insertion, modification, deletion of json elements, and conversion format to string
Copy code The code is as follows:



IT-Homer demo< ;/title> <br></head> <br><br><body> <br><input type="button" id="parse" value="parse json" onclick="parseJson() " /> <br><div id="txt" /> <br><br><script type="text/javascript"> <br>function parseJson(){ <br>var txt = document.getElementById("txt"); <br><br>var jsonData = '{"name":"it-homer","age":25}'; <br>var field = ""; <br> <br>if(jsonData.length <= 0){ <BR>jsonData = '{}'; <BR>} <br><br>var jsonObj = JSON.parse(jsonData); // ok <BR> // var jsonObj = eval('(' jsonData ')'); // ok <BR>// var jsonObj = jsonData.parseJSON(); // error <BR>field = "name = " jsonObj.name; <BR>field = ", age = " jsonObj.age; <br><br>jsonObj["sex"] = "boy"; // add json, {"name":"it-homer","age": 25,"sex":"boy"} <BR>// createJson(jsonObj, "sex", "boy"); <br><br>jsonData = JSON.stringify(jsonObj); // ok <BR>/ / jsonData = jsonObj.toJSONString(); // error <br><br>var sex = ""; <BR>if(jsonObj.length > 0) { <br>sex = jsonObj.sex; <br>} <br><br>txt.innerHTML = field "</br>" jsonData; <br>} <br><br>function createJson(jsonObj, key, value){ <br>if(typeof value === "undefined"){ <br>delete jsonObj[key]; <br>} else { <br>jsonObj[key] = value; <br>} <br>} <br></script> <br>< ;/body> <br></html> <br> </div> <br>Run results: <br><img src="/static/imghw/default1.png" data-src="http://files.jb51.net/file_images/article/201309/2013090816014516.gif?20138816156" class="lazy" alt="js handles common operations such as json and string comparison_javascript skills" > <br>Demo4: <br><br>Compare the different elements of the two strings and Print it out. The two strings have an inclusion relationship, that is, one string must be a substring of the other string. For example, {1,2,4} is a substring of {1,2,3,4,5}<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="73695" class="copybut" id="copybut73695" onclick="doCopy('code73695')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code73695"> <br><html> <br><head> <br><title>IT-Homer demo










Running results:
js handles common operations such as json and string comparison_javascript skills
Demo5:
Copy code The code is as follows:



hello









我,喜,欢

,你

,做,朋,友










运行结果:
js handles common operations such as json and string comparison_javascript skills
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

C++ program to compare the lexicographic order of two strings C++ program to compare the lexicographic order of two strings Sep 04, 2023 pm 05:13 PM

Lexicographic string comparison means that strings are compared in dictionary order. For example, if there are two strings 'apple' and 'appeal', the first string will come last because the first three characters of 'app' are the same. Then for the first string the character is 'l' and in the second string the fourth character is 'e'. Since 'e' is shorter than 'l', it will come first if we sort lexicographically. Strings are compared lexicographically before being arranged. In this article, we will see different techniques for lexicographically comparing two strings using C++. Using the compare() function in C++ strings The C++string object has a compare()

In C/C++, the strcmp() function is used to compare two strings In C/C++, the strcmp() function is used to compare two strings Sep 10, 2023 am 11:41 AM

Thefunctionstrcmp()isabuilt-inlibraryfunctionanditisdeclaredin“string.h”headerfile.Thisfunctionisusedtocomparethestringarguments.Itcomparesstringslexicographicallywhichmeansitcomparesboththestringscharacterbycharacter.Itstartscomp

How to compare strings in c language How to compare strings in c language May 08, 2021 pm 03:05 PM

Comparison methods: 1. bcmp(), compares whether the first n bytes of a string are equal; 2. strcmp(), compares strings in a case-sensitive manner; 3. strictmp(), compares strings in a case-insensitive manner; 4. strncmp() or strnicmp(), case-sensitive comparison of the first n characters of a string.

How to implement string comparison using go language How to implement string comparison using go language Jun 04, 2021 pm 04:13 PM

How to compare strings in Go language: 1. Use the "==" operator, the syntax "String 1 == String 2"; 2. Use the ToLower() function of the strings package; 3. Use the Compare() of the strings package Function that can compare two strings in dictionary order, the syntax is "strings.Compare(str1,str2)"; 4. Use the EqualFold() function of the strings package to compare strings that ignore case, and the return value is of bool type.

How to use STRCMP function to compare the size of two strings in MySQL How to use STRCMP function to compare the size of two strings in MySQL Jul 12, 2023 am 10:13 AM

How to use the STRCMP function in MySQL to compare the sizes of two strings In MySQL, you can use the STRCMP function to compare the sizes of two strings. The STRCMP function compares two strings according to their lexicographic order and returns an integer value representing the comparison result. The syntax of the STRCMP function is as follows: STRCMP(str1,str2) where str1 and str2 are the two strings to be compared. The return values ​​of the STRCMP function are as follows:

How to compare the size of two strings using MySQL's STRCMP function How to compare the size of two strings using MySQL's STRCMP function Jul 27, 2023 pm 07:01 PM

How to compare the size of two strings using MySQL's STRCMP function In MySQL, there are many functions that can be used to compare the size of strings. Among them, the STRCMP function can compare two strings according to their lexicographic order and return an integer value. This article will introduce how to use MySQL's STRCMP function for string comparison and provide corresponding code examples. First, let’s take a look at the basic syntax of the STRCMP function: STRCMP(str1,s

Python program to compare two strings by ignoring case Python program to compare two strings by ignoring case Aug 28, 2023 pm 02:53 PM

In Python, we can use comparison operators such as "==", "!=", "", "=" and Python built-in functions such as lower() and upper() methods to compare two characters by ignoring case string. A string is a sequence of characters enclosed in double quotes. These operators compare strings based on the Unicode code points assigned to each character of the string. In this article, we will learn how to compare two strings by ignoring the case of the strings. Comparing Strings Ignoring Case To compare two strings in Python and ignoring case, we can use the lower() or upper() function to convert the strings to lowercase or uppercase respectively. Once the string is completely converted to small

Compare the size of two strings using Java's String.compareTo() function Compare the size of two strings using Java's String.compareTo() function Jul 25, 2023 pm 05:36 PM

Compare the size of two strings using Java's String.compareTo() function In Java, we can use the compareTo() function of the String class to compare the size of two strings. The compareTo() function returns an integer value used to represent the size relationship between two strings. The method of using the compareTo() function is as follows: publicintcompareTo(Stringstr) where str is the

See all articles