Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数组中对象的变量_Javascript_Html - Fatal编程技术网

Javascript 数组中对象的变量

Javascript 数组中对象的变量,javascript,html,Javascript,Html,想知道是否有可能获得被推入数组的对象的变量或函数 要将数组中的所有对象添加到web页面中,函数将从中获取内容字符串 我目前拥有的: recordjs var recordArray = []; function EmailRecord(name, email) { this.name = name; this.email = email; this.getRecord = function() { return this.name+"|"+this.em

想知道是否有可能获得被推入数组的对象的变量或函数 要将数组中的所有对象添加到web页面中,函数将从中获取内容字符串

我目前拥有的:

recordjs
var recordArray = [];

function EmailRecord(name, email) {
    this.name = name;
    this.email = email;
    this.getRecord = function() {
        return this.name+"|"+this.email;
    };
}   

function addRecord(){
    var n1 = document.getElementById("name").value;
    var e1 = document.getElementById("email").value
    var aRecord = new EmailRecord(n1,e1);
    recordArray.push(aRecord);


}

index.html
<label>Name: </label><input type="text" id="name"/>
<label>Email </label><input type="text" id="email"/>
<br/>
<input type="button" value="Add a record" onclick="addRecord()"/>
<p id="p1"></p>
recordjs
var-recordArray=[];
功能EmailRecord(名称、电子邮件){
this.name=名称;
this.email=电子邮件;
this.getRecord=函数(){
返回此.name+“|”+此.email;
};
}   
函数addRecord(){
var n1=document.getElementById(“名称”).value;
var e1=document.getElementById(“电子邮件”).value
var aRecord=新的电子邮件记录(n1,e1);
recordArray.push(磁带);
}
index.html
姓名:
电子邮件


根据我的建议,您有一个数组,并且希望加入该数组的所有内容

//If you have an array of name array1,
var array1=["value1","value2",....]
//To join all the elements, use below line
var allValues = array1.join();

现在,所有值都将包含“value1 value2…”

所以您想要获取变量的名称或仅仅是内容吗?想要使用内容吗?您的问题非常神秘。请为我们提供一些代码,让我们更好地了解您正在尝试执行的操作。