JavaScript是一门Web编程语言,用来实现网页的交互功能,它和HTML、CSS共同组成了个Web开发的基础工具集合,也是前端开发者必备的技能;学习JavaScript教程可以了解它在网页开发中的所有特性和相关概念,让我们能够更加快速的去开发Web应用。
toSource() 方法返回表示数组源代码的字符串。
版本实现
实现于JavaScript 1.3
语法说明
toSource()
执行一下代码说明
None
示例:
在以下网页文档中,toSource() 方法返回数组 fruits 的源代码。
HTML代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8" />
<title>JavaScript toSource() method example</title>
<style type="text/css">
h1 {color:red}
</style>
</head>
<body>
<h1>JavaScript : toSource() method</h1>
<hr>
<script src="array-tosource-example1.js"></script>
</body>
</body>
</html>
执行一下JS代码
var fruits = new Array("Orange","Apple","Banana","Chery");
var newParagraph = document.createElement("p"); //creates a new paragraph element
var newText = document.createTextNode(fruits.toSource()); //creates text along with ouput to be displayed
newParagraph.appendChild(newText); //created text is appended to the paragraph element created
document.body.appendChild(newParagraph); // created paragraph and text along with output is appended to the document body
执行一下上一篇:JavaScript sort() 方法:数组对象
下一篇:JavaScript toString()方法:数组对象