Associative Arrays in JavaScript

Associative Arrays   Associative arrays are like ordinary arrays except the indices are Strings instead of numbers. The keys in an associative array have to be Strings. The values can be anything, including other arrays or associative arrays.   Example of Associative Array var capital = []; capital["India"] = "Delhi"; capital["Japan"] = "Tokyo"; colsole.log(capital["Japan"]); Output […]

JavaScript for..of loop

for of loop The for…of statement creates a loop iterating over iterable objects (including Array, Map, Set, String, TypedArray, arguments object etc). for..of loop is added in ES6. Check the compatibility table for usage in various browsers.   Syntax : for (variable of iterable_object) {   statement }   Example : Iterating over an array using […]

JavaScript for in loop

for in loop   The for…in statement iterates over the enumerable properties of an object, in arbitrary order. Objects created from built–in constructors like Array and Object have inherited non–enumerable properties from Object.prototype and String.prototype, such as String’s indexOf() method or Object’s toString() method   Syntax for in loop:   for (variable in object) { […]

JavaScript Map

Map Map is introduced in JavaScript with ECMAScript 6. A map is simple key-value pair. Any value (both objects and primitive values) may be used as either a key or a value.   Creating a Map We can create a new map using syntax : new Map() or new Map([iterable]) Iterable is an Array or […]

JavaScript If, else and else if statements

In JavaScript we have the following conditional statements: Use if to specify a block of code to be executed, if a specified condition is true Use else if to specify a new condition to test, if the first condition is false Use else to specify a block of code to be executed, if the same […]