click below
click below
Normal Size Small Size show me how
JAVASCRIPT WEEK 4
Question | Answer |
---|---|
var numbers=new Array("5","12","8"); The numbers[1] is equal to : | 12 |
var numbers=new Array("5","12","8"); document.write(numbers[3]); | The code will display the third value of the array |
var numbers=[25,19,34,17,30]; grades.sort(function(x, y){return x-y}); | Array ascending sort |
var numbers=[25,19,34,17,30]; grades.sort(function(x, y){return y-x}); | Array descending sort |
var colours = ["red", "blue", "yellow"]; document.write(colours.toString()); The result is: | red, blue, yellow |
var colours = ["red", "blue", "yellow"]; document.write(colours.join(" * ")); The result is: | red*blue*yellow |
var colours=["red", "blue", "yellow"]; colours.reverse(); The result is : | yellow blue red |
var colours=["red", "blue", "yellow"]; colours.pop(); The result is: | red blue |
var colours=["red", "blue", "yellow"]; colours.push("green"); The result is: | red,blue,yellow,green |
var colours=["red", "blue", "yellow"]; colours.shift(); The result of the code above is: | blue,yellow |
var colours=["red", "blue", "yellow"]; colours.unshift("green"); The result of the code above is: | green,red,blue,yellow |
var numbers = [10, 20, 40]; students.splice(2,0,30); The result of the code above is: | 10,20,30,40 |
var str=new String("Unicaf University"); document.write(str); The result of the code above is: | Unicaf University |
var str=" Unicaf university "; var final_str=str.trim(); document.write(final_str); The result of the code above is: | Unicaf university |
var str ="UNICAF University"; document.write(str.toLowerCase()); The result of the code above is: | unicaf university |
var str ="unicaf university"; document.write(str.toUpperCase ()); The result of the code above is: | UNICAF UNIVERSITY |
var str1="Unicaf"; var str2="University"; var str_3=str_1.concat(str_2); document.write(str_3); The result of the code above is: | Unicaf University |
var str="unicaf university"; document.write(str.slice(7,10)); The result of the code above is: | uni |
var str="unicaf university"; document.write(str.chartAt (7)); The result of the code above is: | u |
var str="unicaf university"; document.write(str. indexOf("university")); The result of the code above is: | 7 |
var colours=["red", "blue", "yellow"]; delete colours[0]; document.write(colours[0]); The result of the code above is: | undefined |
var colours1=["red", "blue"]; var colours2=["yellow", "green"]; var colours3=colours1.concat(colours2); The result of the code above is: | red,blue,yellow,green |