1 split(' ') 切割符
把字符串分割為數(shù)組 引號間用空格
<div class="app">
<h1>{{huan}}</h1>
</div>
<script>
new Vue({
el:'.app',
data:{
mag:'hell vue'
},
computed:{
huan:function(){
return this.mag.split(' ')
}
}
})
</script>
//輸出結(jié)果為:[ "hell", "vue" ]
2 join 拼接符
<div class="app">
<h1>{{huan}}</h1>
</div>
<script>
new Vue({
el:'.app',
data:{
mag:'hell vue'
},
computed:{
huan:function(){
return this.mag.split(' ').join
}
}
})
</script>
//輸出結(jié)果為:hell,vue
3 reverse 翻轉(zhuǎn)
<div class="app">
<h1>{{huan}}</h1>
</div>
<script>
new Vue({
el:'.app',
data:{
mag:'hell vue'
},
computed:{
huan:function(){
return this.mag.split(' ').reverse
}
}
})
</script>
//輸出結(jié)果為:[ "vue", "hell" ]
4 *** string***
把對象的值轉(zhuǎn)為字符串
<button onclick="myFunction()">點(diǎn)擊</button>
<script>
function myFunction(){
var ff= ["Banana", "Orange", "Apple", "Mango"];
var str = ff.toString();
var a=document.getElementById("demo");
a.innerHTML= str;
}
</script>
5 concat 用于連接兩個或多個數(shù)組
<script type="text/javascript">
var a = [1,2,3];
document.write(a.concat(4,5));
</script>
//輸出結(jié)果為:1,2,3,4,5
6 slice
從已有的數(shù)組中返回選定的元素
<script>
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
document.write(arr.slice(2,4) + "<br />")
</script>
//輸出結(jié)果為:Thomas,James
7 splice('坐標(biāo)下添加 '‘刪除0個或一個’)
從數(shù)組中添加/刪除項(xiàng)目办陷,然后返回被刪除的項(xiàng)目
<script>
var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
arr.splice(2,0,"William")
document.write(arr)
</script>
//輸出結(jié)果為:George,John,William,Thomas,James,Adrew,Martin
8 ***push() ***
向數(shù)組的末尾添加一個或多個元素乡洼,并返回新的長度责静。
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.push("James") )//輸出結(jié)果為:4
document.write(arr)//輸出結(jié)果為:George,John,Thomas,James
9 pop()
刪除并返回?cái)?shù)組的最后一個元素。
<script>
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.pop())
document.write(arr)
</script>
//輸出結(jié)果為:Thomas
//輸出結(jié)果為:George,John
10 unshift
向數(shù)組的開頭添加一個或更多元素斤富,并返回新的長度
<script type="text/javascript">
var arr = new Array()
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.unshift("William") + "<br />")
document.write(arr)
//輸出結(jié)果為:
George,John,Thomas
4
William,George,John,Thomas
11 shift()
把數(shù)組的第一個元素從其中刪除圾旨,并返回第一個元素的值妙黍。
<script type="text/javascript">
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr + "<br />")
document.write(arr.shift() + "<br />")
document.write(arr)
</script>
//輸出結(jié)果為:
George,John,Thomas
George
John,Thomas