2017-05-30 62 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 ...」

相關問題