Javascript学习笔记——7.12 作为数组的字符串

2018-06-14  本文已影响0人  IFELSE

字符串除了使用charAt()方法访问单个字符外,还可以用方括号。

var s = "hello world"
s.charAt(3) //l
s[3] //l
typeof(s)
//"string"
Array.isArray(s)
//false
var s = "abcde"
var s1 = Array.join(s,",")
console.log(s1)
// a,b,c,d,e
console.log(s)
// abcde
s1 = Array.prototype.join.call(s,",")
console.log(s1)
// a,b,c,d,e
console.log(s)
// abcde
s1 = Array.filter(s,function(x){return x<'d'}).join()
console.log(s1)
// abc
上一篇下一篇

猜你喜欢

热点阅读