一天JavaScript示例-在功能上的标量参数和数组参数的差异

时间:2023-11-28 16:24:38
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-标量參数和数组參数的功能性差别</title>
<script>
window.onload = function(){
var items = new Array('apple','orange','cherry','lime');
var sep = "*";
func(items,sep);
console.log(items);
console.log(sep);
}
function func(strings,separator){
var result = "";
//console.log(strings.length);
for(var i = 0; i < strings.length; i++){
result+= strings[i] + separator;
}
separator = result;
strings[strings.length] = result; }
</script>
</head> <body>
</body>
</html>