为什么数组字符串用逗号分隔?

时间:2018-05-07 12:41:50

标签: javascript arrays

我试图根据用户输入的信息制作一个列表。

   var todoArray = new Array();

document.getElementById("addButton").onclick = function(){

    var temp = document.getElementById("inputBox").value;
    var appendTemp = "<li><input type=\"checkbox\">" + temp + "</li>";

    todoArray.push(appendTemp);

    document.getElementById("todoListUL").innerHTML = todoArray;

    console.log(todoArray);

}

但是当列表时间显示时,它们之间都有逗号,JSFiddle链接用于图像:JSFiddle

为什么它们用逗号分隔,如何删除它?

2 个答案:

答案 0 :(得分:4)

将任何值分配给元素的.innerHTML属性时,该值将隐式转换为字符串,然后解析为HTML。数组转换为字符串的默认方式是通过.join()方法,默认数组分隔符是逗号。

如果您不需要任何内容​​,可以自己致电.join()

document.getElementById("todoListUL").innerHTML = todoArray.join("");

答案 1 :(得分:1)

问题出在这一行:

<?php $multiCurl = array();  

 $result = array();

 $mh = curl_multi_init();

 foreach ($members as $mem => $id) {
$c = $mem["ta"];
$urll = "https://api.abcd.com/" . urlencode($c);
$tokenq = "abcd";
$multi[$mem] = curl_init();
 $headr = array();
$headr[] = "Accept: application/json";
 $headr[] = "Authorization: Bearer ".$tokenq;
 curl_setopt($multi[$mem], CURLOPT_HTTPHEADER,$headr);
 curl_setopt($multi[$mem], CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($multi[$mem], CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($multi[$mem], CURLOPT_RETURNTRANSFER,1);
 curl_multi_add_handle($mh, $multi[$mem]);
  }
 $index=null;
  do {
 curl_multi_exec($mh,$index);
 } while($index > 0);
 // get content and remove handles
 foreach($multi as $kp => $ch6) {
 $result[$kp] = curl_multi_getcontent($ch6);
  curl_multi_remove_handle($mh, $ch6);
  }
  // close
  curl_multi_close($mh);

因为正确的成员已转换为document.getElementById("todoListUL").innerHTML = todoArray; ,并且string数组的join方法在内部调用,默认todoArraydelimiter

将其更改为

comma