JavaScript中的String()函數與示例

String()函數 (String() function)

String() function is a predefined global function in JavaScript, it is used to convert an object to the string.

String()函數是JavaScript中預定義的全局函數,用于將對象轉換為字符串。

Example:

例:

In this example, we are going to convert different object’s values to the string.

在此示例中,我們將把不同對象的值轉換為字符串。

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>		
var a = "10";	
var b = "10 20";
var c = "1234 Hello";
var d = "Hello 1234";
var e = true;	
var f = new Date();
//converting values to string using String() function
document.write("String(a) = " + String(a) + "<br>");
document.write("String(b) = " + String(b) + "<br>");
document.write("String(c) = " + String(c) + "<br>");
document.write("String(d) = " + String(d) + "<br>");
document.write("String(e) = " + String(e) + "<br>");
document.write("String(f) = " + String(f) + "<br>");
</script>
</body>
</html>

Output

輸出量

String(a) = 10
String(b) = 10 20
String(c) = 1234 Hello
String(d) = Hello 1234
String(e) = true
String(f) = Sat Feb 02 2019 23:03:12 GMT+0530 (India Standard Time)

翻譯自: https://www.includehelp.com/code-snippets/String-function-with-example-in-javascript.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379705.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379705.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379705.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ASCII碼排序(C++)

題目描述: 輸入三個字符&#xff08;可以重復&#xff09;后&#xff0c;按各字符的ASCII碼從小到大的順序輸出這三個字符。 輸入描述: 第一行輸入一個數N,表示有N組測試數據。后面的N行輸入多組數據&#xff0c;每組輸入數據都是占一行&#xff0c;有三個字符組成&#xff0c;…

FreeRTOS--堆內存管理(二)

堆內存管理代碼具體實現heap_1內存申請函數內存釋放函數heap_2內存塊內存堆初始化函數內存塊插入函數內存申請函數判斷是不是第一次申請內存開始分配內存內存釋放函數heap_3heap_4內存堆初始化函數內存塊插入函數heap_5上一篇文章說了FreeRTOS實現堆內存的原理&#xff0c;這一…

在查詢的結果中添加自增列 兩種方法

解決辦法《一》&#xff1a; 在SQL Server數據庫中表信息會用到Identity關鍵字來設置自增列。但是當有數據被刪除的話&#xff0c;自增列就不連續了。如果想查詢出這個表的信息&#xff0c;并添 加一列連續自增的ID&#xff0c;可用如下查詢語句&#xff1a; SELECT Row_Nu…

一個非常簡單的C#面試題

怎樣實現對所有類可讀但是在同一個assembly可寫那&#xff1f; 答案&#xff1a; 同一個assembly namespace ClassLibrary1 { public class Class1 { public string Name { get; internal set; } } public class Class2 { public void GS() { Class1 cc new Class1(); cc.Name…

css中的node.js_在Node App中使用基本HTML,CSS和JavaScript

css中的node.jsYou may think this is not important, but it is!. As a beginner in node.js, most coding exercises are always server sided. 您可能認為這并不重要&#xff0c;但確實如此&#xff01; 作為node.js的初學者&#xff0c;大多數編碼練習始終都是服務器端的。…

Binary String Matching(C++)

題目描述: Given two strings A and B, whose alphabet consist only ‘0’ and ‘1’. Your task is only to tell how many times does A appear as a substring of B? For example, the text string B is ‘1001110110’ while the pattern string A is ‘11’, you should…

由一次代碼優化想到的Js 數據類型

引子&#xff1a; 上周三進行了代碼優化&#xff0c;其中有一個很普遍的代碼&#xff0c;例如&#xff1a; if(test "") {dothis();}else{dothat()} ----->可以簡化為 !test ? dothis():dothat(); if(test "") {dothis()}     ----->可以簡化為…

VisualStudio2019配置OpenCV

VisualStudio2019配置OpenCV配置0x01 準備0x02 配置系統環境0x03 復制文件0x04 配置VisualStudio2019測試配置 0x01 準備 下載opencv&#xff0c;官網地址&#xff1a;https://opencv.org/releases/# 下載之后&#xff0c;自行安裝 0x02 配置系統環境 找到高級系統設置 …

轉載 Javascript的IE和Firefox兼容性匯編

微軟關于IE、Firefox、Opera和Safari的JavaScript兼容性研究曾經發表過一份草案,可以點擊下載《JScript Deviations from ES3》 以下為網上的一些搜集和整理(FF代表Firefox) 集合類對象問題現有代碼中存在許多 document.form.item("itemName") 這樣的語句&#xff0c…

存儲器間接尋址方式_8086微處理器的程序存儲器尋址模式

存儲器間接尋址方式The Program Memory Addressing mode is used in branch instructions. These branch instructions are instructions which are responsible for changing the regular flow of the instruction execution and shifting the control to some other location…

Servlet的配置

1&#xff0c;基本配置 <!-- Servlet類的配置 --><servlet><servlet-name>sq</servlet-name><servlet-class>beyond.servlet.QuickStartServlet</servlet-class></servlet><!-- Servlet的虛擬路徑的配置 --> <servlet-mapp…

Asp.net頁面生存周期

# 事件或方法 功能 描述   1 Init 事件 頁面初始化 初始化設置。   2 LoadViewState 方法 加載視圖狀態 填充ViewState屬性。   3 LoadPostData 方法 處理回發數據 處理傳入窗體數據。   4 Load 事件 加載頁面 頁面控件初始化完成并反映了客戶端的數據。   5 RaisePo…

你正確關閉WCF鏈接了嗎?

通常情況下我們關閉一個WCF鏈接都是簡單地寫把ICommunicationObject.Close()方法&#xff0c;但是這個方法有個問題就是當調用發生異常時&#xff0c;Close()會發生次生的異常&#xff0c;導致鏈接不能正常關閉。如果當這種異常很多時&#xff0c;必然對系統的穩定性有很大的影…

Visual Studio進行linux遠程開發

目錄準備工作創建一個項目配置遠程項目準備工作 查看linux IP地址 安裝了工具 sudo apt-get install openssh-server g gdb make ninja-build rsync zip開啟ssh服務&#xff1a; sudo service ssh startVS2019按裝了linux功能&#xff0c;如果沒有&#xff0c;找到Visual S…

在給定總和K的二叉樹中找到級別

Description: 描述&#xff1a; The article describes how to find the level in a binary tree with given sum K? This is an interview coding problem came in Samsung, Microsoft. 本文介紹了如何在給定總和K下在二叉樹中找到級別 &#xff1f; 這是一個面試編碼問題&a…

PostgreSQL學習手冊(數據庫維護) 轉

原文&#xff1a; PostgreSQL學習手冊(數據庫維護)一、恢復磁盤空間&#xff1a;在PostgreSQL中&#xff0c;使用delete和update語句刪除或更新的數據行并沒有被實際刪除&#xff0c;而只是在舊版本數據行的物理地址上將該行的狀態置為已刪除或已過期。因此當數據表中的數據變化…

++i與i++的根本性區別(兩個代碼對比搞定)

首先來看i 代碼如下&#xff1a; #include <stdio.h> #include <stdlib.h> int main() {int i0;int ai;printf("%d\n",a);printf("%d\n\n\n",i);return 0; }輸出結果如下&#xff1a; 解釋&#xff1a;i其實是兩行代碼的簡寫形式&#xff0c…

國企和外企的比較

由于本人在外企&#xff0c;而很多朋友在國企&#xff0c;因此我個人的說法應該還是有一定的權威性。 首先&#xff0c;國企和外企不能一概而論。正如任何事物都有三六九等&#xff0c;這個&#xff0c;只能在同等級別上進行比較。 國企分類&#xff1a; 一等國企&#xff1…

Python | 使用matplotlib.pyplot創建線圖

Problem statement: Write a program in python (using matplotlib.pyplot) to create a line plot. 問題陳述&#xff1a;用python編寫程序(使用matplotlib.pyplot)以創建線圖。 Program: 程序&#xff1a; import matplotlib.pyplot as pltx [1,2,3,4,5,6,7,8,9,10]y [3,…

QI(接口查詢)

接觸AE一段時間了&#xff0c;總的來說收獲不少&#xff0c;今天仔細分析了一下AE開發中經常會用到的QI即接口查詢&#xff0c;有了自己的一些理解。 COM類至少有一個接口。事實上一般它們有好幾個接口。即一個類經常會實現多個接口&#xff08;一個類無法繼承多個類&#xff0…