Javascript: Set object & Loop

A Set object holds the unique values of any type like array or object. An array or any other iterable object can be passed to Set. – It’s a new data structure introduced in JavaScript ECMAScript 6 (ES6). – It has useful methods for iteration over the Set values. var mySet = new Set(); mySet.add(11); … Read more

Javascript: Map object & Loop

A Javascript Map object holds the key-value pairs of elements. An array or any other iterable object can be passed to the Map. – Map is a new data structure introduced in JavaScript ES6. – It’s an alternative to JavaScript Object for storing key/value pairs. – It has useful methods for iteration over the key/value … Read more

Javascript: Object & Loop

This article deals with creating a Javascript object and using different functions on the object. We also see how we can loop through the object and get the values. Create a new Javascript Object var myObject = { fruit: 'apple', flower: 'rose', vegetable: 'cabbage' }; console.log(myObject); // {fruit: "apple", flower: "rose", vegetable: "cabbage"} Access elements … Read more

Javascript: Check if a variable is an Object

This article shows how you can check if a Javascript variable is of an Object type. There are different ways to check if a variable is an Object in Javascript. 1) First way // define an object var myObject = {id: 11, name: John} console.log(Object.prototype.toString.call(myObject)); // [object Object] // check if the variable is an … Read more

Javascript: Populate Select box OnChange with JS array/object

This article show how to populate one select box by selecting option of another select box/list. We will use a Javascript object. Each key of the object contains array as value. A first select box is populated with the Javascript object’s keys. Then when the value from the first select box is selected then based … Read more

jQuery: Print array and object

This article shows how to print array and object on jQuery. You can do it with jQuery.each() function. jQuery.each() function can be used to iterate over any collection, whether it is a map (JavaScript object) or an array. Here is the javascript code to print array or object: jQuery(document).ready(function(){ var arr = [ "earth", "mars", … Read more

print_r in Javascript

It’s a real headache when you have to work on objects and arrays in Javascript. It would be lot easier to detect elements of the Javascript objects/arrays if we have print_r function in Javascript like we have in PHP. I googled the web and have found a very efficient print_r Javascript function. Here is the … Read more