【问题标题】:variable of a object in an array数组中对象的变量
【发布时间】:2017-10-30 21:37:30
【问题描述】:

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

我目前拥有的:

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>

【问题讨论】:

  • 所以你想获取变量名还是只获取内容?
  • 想要使用的内容
  • 你的问题很神秘。请向我们提供一些代码,以便我们更好地了解您要执行的操作。

标签: javascript html


【解决方案1】:

根据我的理解,你有一个数组,你想加入数组的所有内容。

//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 ...”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 2021-07-11
    • 2015-06-14
    • 2015-09-08
    相关资源
    最近更新 更多