if (...) { ... } else if(...) { ... } else { ... } // 三目运算符 name ? console.log("存在:"+name) :console.log("不存在") //多条件下的三目运算符 0 ? console.log(1) : 3>4 ? console.log(2) : console.log(3)
var choice = 1; switch (choice) { case 1: document.write(1); //不写break时,当满足条件是,不再判断,会执行后面所有语句 break; case 2: document.write(2); break; default: document.write("都不满足"); }
//九九乘法表 for (i=1; i<=9; i++){ for(j=1; j<=i; j++){ document.write(j+"*"+i+"="+i*j+' '); } document.write("<br>"); }
while (true){ document.write(1); break; }
do{ document.write(1); }while (1<0)
var str_test = "which love love"; document.write(str_test.length+'<br>');//length document.write(str_test[0]+'<br>');//[] document.write(str_test.charat(1)+'<br>');//charat() document.write(str_test.replace("love","===")+'<br>');//replace() document.write(str_test.split(' ')+'<br>');//split() document.write(str_test.touppercase()+'<br>');//touppercase() document.write(str_test.tolowercase()+'<br>');//tolowercase() document.write(str_test.indexof('l',8)+'<br>');//indexof() //slice()不会自动比较参数的大小 document.write(str_test.slice(0,5)+'<br>');//slice() //substring()会自动比较参数的大小 document.write(str_test.substring(5,0)+'<br>');//substring()
var arr = ['one','two','three','four','five']; document.write(arr.length+'<br>');//length document.write(arr[0]+'<br>');//[] arr.push('six');//push() arr.unshift('zero');//unshift(),从前面添加 arr.pop();//pop() arr.shift();//shift() document.write(arr.indexof('two')+'<br>');//indexof() document.write(arr.slice(0,3)+'<br>');//slice() //将新的值,替换从下标为1的开始的两个值 document.write(arr.splice(1,2,'a','b','c','d')+'<br>');//splice() document.write(arr.join('==')+'<br>');//join() document.write(arr.sort()+'<br>');//sort() document.write(arr.reverse()+'<br>');//reverse() var arr_temp1=[1,2]; var arr_temp2=[3,4]; document.write(arr.concat(arr_temp2,arr_temp1)+'<br>');//concat()
var num = 12.8; var a ='0x1234'; var b ='343.324'; document.write(typeof tostring(num)+'<br>');//tostring() document.write(num.tofixed()+'<br>');//tofixed() document.write(isnan(num)+'<br>');//isnan() document.write(array.isarray(num)+'<br>');//isarray() document.write(parseint(a)+'<br>');//parseint() document.write(parsefloat(b)+'<br>');//parsefloat() document.write(number(b)+'<br>');//number()
如对本文有疑问, 点击进行留言回复!!
【SCAU18新生赛 论剑】 18362 寻找Megumi 多源最短路
网友评论