想知道是否有可能获得被推入数组的对象的变量或函数 想要添加数组中的所有对象,其中函数将获取内容的字符串到网页
我现在拥有的东西:
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)
根据我的说明,你有一个数组,你想加入数组的所有内容。
//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 ...”