- substr() :
if("hello world".substr(0, 5) == "hello"){
console.log(true);
}
- substring() :
if("hello world".substring(0, 5) == "hello"){
console.log(true);
}
- slice():
if("hello world".slice(0, 5) == "hello"){
console.log(true);
}
- indexOf():
if("hello world".indexOf("hello") == 0) {
console.log(true);
}
- search()
if("hello world".search("hello") == 0) {
console.log(true);
}
- test()
if(new RegExp("^abc.*$").test("abcdefg")) {
console.log(true);
}
- match()
if("abcdefg".match(new RegExp("^ab.*$"))) {
console.log(true);
}
返回数组最大值和最小值
let array=[1,2,3,4,5,6,7,8,9,0]
//查询最大值
var maxValue = Math.max.apply(Math, array);
//查询最小值
var minValue = Math.min.apply(Math, array);
最新小程序案例