var strArr = ['i','am','jontyy'];
console.log(strArr.join()); //i,am,jontyy
console.log(strArr.join('-')); //i-am-jontyy
console.log(strArr.join('')); //iamjontyy
//字符串转数组是 split方法
2. indexof() 查找索引值下标 / lastIndexof() 反向查找
3. concat() 拼接,原数组末尾添加n项
4. slice(start,[end]) 截取(不包括end) *****
var arr = [ 1, 2, 3, 4, 5, 6 ];
console.log( arr.some( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item > 3;
}));
console.log( arr.every( function( item, index, array ){
console.log( 'item=' + item + ',index='+index+',array='+array );
return item > 3;
}));
//item=1,index=0,array=1,2,3,4,5,6
//item=2,index=1,array=1,2,3,4,5,6
//item=3,index=2,array=1,2,3,4,5,6
//item=4,index=3,array=1,2,3,4,5,6
//true
//item=1,index=0,array=1,2,3,4,5,6
//false
some一直在找符合条件的值,一旦到,则不会继续迭代下去。
every从迭代开始,一旦有一个不符合条件,则不会继续迭代下去。
2. filter() 过滤 —不修改原数组
var ages = [32, 33, 16, 40];
function checkAdult(age) {
return age >= 18;
}
function myFunction() {
console.log(ages.filter(checkAdult));//[32,33,40]
/
map() 映射(遍历修改返回) —不修改原数组
var objarr = [
{ id: 1, name: 'renzejun' },
{ id: 2, name: 'xiaokechao' },
{ id: 3, name: 'zhoujun' }
];
var newarr = objarr.map((ele, index, objarr) => {
return ele.id
});
console.log(newarr);//[1,2,3]
arr.forEach((index,ele,arr) => {
})
var a = [1,2,3,4,5,6,7,8,9,10]
var str = a.reduce(function(prev,cur,index,arr){
return prev + cur ;
});
str //55
'hello'.indexOf('ll',0);
//2
'asdasdasdasd'.replace('a','---')
//"---sdasdasdasd"