DONATE  
MENU
PHP
JSON
HTML
CSS
MYSQL
AJAX
JAVASCRIPT

JavaScript Tutorials

INTRODUCTION

» Introduction to JavaScript

» Practice IT Editor

» JavaScript Example

» JavaScript Placement

» JavaScript Syntax

» JavaScript Statements

» JavaScript Input

» JavaScript Output

» JavaScript Comments

» JavaScript Variables

» Variables' Scope

» JavaScript Operators

» JS Expressions & Concatenation

» JavaScript Data Type

» JavaScript Numbers

» Number Object

» JavaScript Strings

» String Object

» JavaScript Booleans

» Boolean Object

» JavaScript Functions

» JavaScript Arrays

» Array Object - Properties

» Array Object - Methods

» JavaScript Objects

» JavaScript Undefined

» JavaScript Nulls

CONDITIONAL TESTING

» If Statement

» If Else Statement

» JavaScript Ternary Operator

» Switch Statement

LOOPS

» For Loops

» While Loops

» Break & Continue

» For...In Loops

» do...while Loop

FUNCTIONS

» JavaScript Functions

» Creating Functions

» Functions' Parameters

» Functions' Arguments

» Function Invocation

» The Return Keyword

» The Arguments Object

» Callback Functions

» Arrow Functions

ARRAYS

» JavaScript Arrays

» Creating Arrays

» Accessing Arrays

» Looping Arrays

» Multi - dimensional Arrays

OBJECTS

» JavaScript Objects

» Creating Objects

» Prototype Definition

» Accessing Objects

» The this Keyword

AJAX

» Introduction to AJAX

JSON

» Introduction to JSON

JAVASCRIPT DATES

» The Date Object

» Date Methods

» Timing (SetInterval & SetTimeout)

MATH OBJECT

» Math Object

» Math Methods

HTML / JS DOM

» DOM Introduction

» Accessing HTML Elements in DOM

» Get And Change Elements' Contents & Values

» Change Styling - DOM CSS

» DOM Attributes

» JavaScript Event Listeners

» DOM Event Listeners

» JS Events

MISCELLANEOUS

» JS Strict Mode

» JavaScript Hoisting

» JavaScript let keyword

» Reserved Keywords

» JS Best Practices

» JavaScript vs ECMAScript

JAVASCRIPT EXAMPLES

» JavaScript Calculator

.. » JavaScript » Arrays » Creating Arrays
Share Tweet WhatsApp

Creating Arrays

Arrays in JavaScript are objects and that is why if you use the typeof function on a variable containing an array, it will return an 'object'.
<script>
var arr = [1, 2, 3];
alert(typeof(arr));
</script>

Copy PRACTICE IT

You will learn more about objects in subsequent pages but understand that objects are more like arrays containing properties and methods. The reason for all the above explanation is to bring to your knowledge that arrays can be created the explicit or literal way(easiest and recommended) and the implicit or object way(not really recommended but does same thing). The Explicit Method This method involves having all the values of any array in a bracket ([ ]) while separating each value from the other with a comma (,).
var arr = [value1, value2, ...];
var myArray = [1, 2, 3, 4];
The Implicit Method This method involves creating an array just the way you create new objects out of the prototype of an object in JavaScript using the new keyword. You will learn about this in subsequent pages. So, to create arrays this way, you simply have your various values contained and separated with a comma(,) inside the new Array() object.
var arr = new Array(value1, value2, ...);
var myArray = new Array(1, 2, 3, 4);
The explicit and implicit methods of creating arrays does same thing which is to create an array or a new array. Remember also that any array can contain values of just any data type. Be it numbers, strings, booleans, arrays, objects and functions. SUMMARY
  1. Arrays can be created the explicit or implicit way.
  2. The explicit way involves having your numerous array values inside a bracket ([ ]).
  3. The implicit method involves the direct creation of an array from the array object, Array. We use the new keyword alongside the array object and have our individual values inside of it e.g new Array(1, 2, 4).
  4. Individual values of an array are separated with a comma(,) and the values can be of just any data type including other arrays.
  5. Both the explicit and implicit methods of creating an array does same thing which is to create an array.
Take a short quiz on Creating Arrays.
Ask a question or tell us if Creating Arrays is easy or not.
cent?

Join our 1,090 subscribers to receive tutorials' updates!

  We won't spam your mail box. We hate it.





StackBeginner 2021 © Joseph Omamode