Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Array() > Array() Parameters

Array() Parameters

You can pass the values of an array instance to the constructor as comma-separated parameters (e.g., new Array('foo', 'bar');). The Array() constructor can take up to 4,294,967,295 parameters.

However, if only one parameter is sent to the Array() constructor, and that value is an integer (e.g., 1, 123, or 1.0), then it will be used to set up the length of the array, and will not be used as a value contained within the array.

Live Code

<!DOCTYPE html><html lang="en"><body><script>

var foo = new Array(1, 2, 3);
var bar = new Array(100);

console.log(foo[0], foo[2]); // logs '1 3'
console.log(bar[0], bar.length); // logs 'undefined 100'

</script></body></html>

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint