Array unshift()
In this chapter you will learn:
Array unshift()
unshift()
adds items to the front of an
array and returns the new array length.
<!DOCTYPE html><!--from ja v a 2 s.c o m-->
<html>
<head>
<script type="text/javascript">
var colors = new Array(); //create an array
var count = colors.unshift("A", "B"); //push two items
document.writeln(count); //2
count = colors.unshift("C"); //push another item on
document.writeln(count); //3
var item = colors.pop(); //get the first item
document.writeln(item); //"B"
document.writeln(colors.length); //2
</script>
</head>
<body>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- What is JSON
- What is JSON Syntax
- How to use JSON to represent simple values
- How to use JSON to represent objects
- How to use JSON to represent arrays
Home » Javascript Tutorial » Array