2017-05-30 44 views
-6

想知道是否有可能获得被推入数组的对象的变量或函数 想要添加数组中的所有对象,其中该函数将获得字符串内容以网页数组中对象的变量

我目前有:

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> 
+0

所以你想了解的变量或只是内容的名字吗? –

+0

想要使用的内容 –

+2

你的问题是相当神秘。请为我们提供一些代码,让我们更好地了解您要做的事情。 –

回答

0

按我udnerstanding你有一个数组,你想加入数组中的所有内容。

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

现在allValues将包含“VALUE1 VALUE2 ...”