JavaScript join() 方法

/**
* function join(seperator)
* @param {String} seperator
* @returns {Array}
* @memberOf Array
* @see Array
* @since Standard ECMA-262 3rd. Edition
* @since Level 2 Document Object Model Core Definition.
* @see http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/ecma-script-binding.html
*/
Array.prototype.join = function(seperator){return [];};



<html>
<body>

<script type="text/javascript">

var arr = new Array(3);
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"

document.write(arr.join());

document.write("<br />");

document.write(arr.join("."));

</script>

</body>
</html>



查看结果:
George,John,Thomas
George.John.Thomas



var newText = "<span>" + $("p").text().split(" ").join("</span> <span>") + "</span>";



This will put span tags around all the words in you paragraphs, turning
<p>Test is a demo.</p> 


into
<p><span>Test</span> <span>is</span> <span>a</span> <span>demo.</span></p> 




var arr = [ "a", "b", "c", "d", "e" ]

$("div").text(arr.join(", "));

arr = jQuery.map(arr, function(n, i){
return (n.toUpperCase() + i);
});


$("p").text(arr.join(", "));

arr = jQuery.map(arr, function (a) { return a + a; });

$("span").text(arr.join(", "));



1./*  
2.JScript does not default the separator to “,” if the separator value is undefined.
3.*/
4. var array = [1, 2];
5. alert(array.join());
6. alert(array.join(undefined));
7. alert(array.join('-'));
8./*
9.Output:
10. IE: 1,2 1undefined2 1-2
11. FF: 1,2 1,2 1-2
12. Opera: same as FF
13. Safari: same as FF
14.*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值