1 数组对象
<script>
var arr1 = [‘百度‘, ‘腾讯‘, ‘阿里‘];
var arr2 = [‘360‘, ‘小米‘, ‘锤子‘];
var new_arr = arr1.concat(arr2); // 合并数组,生成一个新的数组
console.log(new_arr); // Array [ "百度", "腾讯", "阿里", "360", "小米", "锤子" ]
</script>
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
var res = arr.join(‘-‘);
console.log(res); // 百度-腾讯-阿里
</script>
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
arr.push(‘360‘);
console.log(arr); // Array [ "百度", "腾讯", "阿里", "360" ]
</script>
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
arr.pop();
console.log(arr); // Array [ "百度", "腾讯" ]
</script>
1.5 shift():删除第一个元素
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
arr.shift();
console.log(arr); // Array [ "腾讯", "阿里" ]
</script>
1.6 unshift():向数组开头添加元素
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
arr.unshift(‘360‘);
console.log(arr); // Array [ "360", "百度", "腾讯", "阿里" ]
</script>
1.7 reverse():颠倒数组的顺序
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
arr.reverse();
console.log(arr); // Array [ "阿里", "腾讯", "百度" ]
</script>
1.8 slice(start, end):截取数组的元素
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
var new_arr = arr.slice(0,2); // 参数1:开始下标;参数2:结束下标
console.log(new_arr); // Array [ "百度", "腾讯" ]
</script>
1.9 splice():删除数组的元素
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
// 参数1:开始的索引位置; 参数2:删除元素的个数
// 参数3(可选):代替删除的内容
arr.splice(0, 2, ‘360‘);
console.log(arr); // Array [ "360", "阿里" ]
</script>
1.10 toString():将数组转换为字符串
<script>
var arr = [‘百度‘, ‘腾讯‘, ‘阿里‘];
var res = arr.toString();
console.log(res); // 百度,腾讯,阿里
</script>
2 字符串对象
2.1
indexOf():获得字符在字符串中第一次出现的位置
<script>
var str = ‘helloworld‘;
var index = str.indexOf(‘l‘);
console.log(index); // 2
</script>
2.2 lastIndexOf():获得字符在字符串中最后一次出现的位置
<script>
var str = ‘helloworld‘;
var index = str.lastIndexOf(‘l‘);
console.log(index); // 8
</script>
2.3 split():按照分隔符将字符串拆分为数组
<script>
var str = ‘www.baidu.com‘;
var arr = str.split(‘.‘);
console.log(arr); // Array [ "www", "baidu", "com" ]
</script>
2.4 replace(a, b):将a替换为b
<script>
var str = ‘helloworld1234‘;
var res = str.replace(/\d+/, ‘!‘);
console.log(res); // helloworld!
</script>
2.5 charAt(index):查找在index这个索引处的字符
<script>
var str = ‘hello‘;
var res = str.charAt(4);
console.log(res); // o
</script>
<script>
var str = ‘hello‘;
var res = str.slice(0,3);
console.log(res); // hel
</script>
<script>
var str = ‘helloworld‘;
var res = str.substr(0,5);
console.log(res); // hello
</script>
2.8 toLowerCase():将字符串转换为小写
<script>
var str = ‘HELLOworld‘;
var res = str.toLowerCase();
console.log(res); // helloworld
</script>
2.9 toUpperCase():将字符串转换为大写
<script>
var str = ‘HELLOworld‘;
var res = str.toUpperCase();
console.log(res); // HELLOWORLD
</script>