Learn six different ways to create an object in JavaScript. image by Dawid ZawiĹ‚a There are multiple ways to create Object in Javascript, I have listed six of them which I learned while reading. So I would like to share that with all JavaScript geeks here. First Way → Using Assignment This is how most of …
Tag Archives: Javascript tips
Different ways to remove elements from an array in JavaScript
Image by Michael Dziedzic From UnSplash 1. Using the pop method Array.pop will delete the last element of an array. var array = [1,2,3,4,5]; array.pop(); array; // [1,2,3,4] array.pop(); array; // [1,2,3] 2. Using the shift method Array.shift will delete the first element of an array. var array = [1,2,3,4,5]; array.shift(); array; // [2,3,4,5] array.shift(); array; // [3,4,5] …
Continue reading “Different ways to remove elements from an array in JavaScript”
Using the every() and some() methods of Array in JavaScript
Learn how to use every and some method in JavaScript. every → Checks if all elements of the array satisfies the provided callback function some → Checks if any one of element in the array satisfies the provided callback function every The every method will take a testing function as an argument, all the element …
Continue reading “Using the every() and some() methods of Array in JavaScript”
Creating a PDF Viewer in JavaScript
Learn how to create a PDF viewer in Javascript using PDF.js PDF.js is a JavaScript library maintained by Mozilla and designed for handling PDFs in JavaScript. Implementing PDF js We are going to create a PDF viewer which will have the following functionality: View a PDF Go to the next page Go to the previous page Go …
Implementing Set functionality in JavaScript
Learn how to implement union ,intersection , difference , symmetricDifference in JavaScript. Image from Javier Quesada The Set object lets you store unique values of any type, whether primitive values or object references. Example var array = [1,2,3,4,4,5]; var set = new Set(array); set; // Set(5) {1, 2, 3, 4, 5} duplicates are removed The detailed introduction to Set …
Continue reading “Implementing Set functionality in JavaScript”
Detecting Online/Offline Status in Javascript
Learn how to detect if the user is online or offline and handle events if a change in the online/offline state occurs. We can detect if the user is online or offline by using the online property on the navigator object which will return true if the user is connected to the internet, otherwise it returns …
Continue reading “Detecting Online/Offline Status in Javascript”
Find the difference between Dates in JavaScript
Learn how to find difference between two dates in JavaScript. Image from Lukas Blazek We learn about finding Number of Seconds , Number of Minutes , Number of hours , Number of days , Number of weeks , Number of months , Number of years between two dates. Let’s create two dates let d1 = Date.now(); let d2 = new Date(2019,5,22).getTime(); //Jun …
Continue reading “Find the difference between Dates in JavaScript”
Understanding Switch Statements in JavaScript
Image from negative space Whenever we are in situation of writing multiple if/else statement for a particular test case, then the multiple if/else statement can be replaced by switch statement. Syntax : switch(expression_or_value) {case expression_or_value : operation1 [break]; case expression_or_value : operation2 [break]; … default : default operation [break]; } // break is optional A switch statement …
Continue reading “Understanding Switch Statements in JavaScript”
Insert an element in specific index in JavaScript Array.
Learn how to insert an element in specific index in array. Image from unsplash (Zdennek) We have some in-built methods to add at elements at the beginning and end of the array. push(value) → Add an element to the end of the array. unshift(value) → Add an element to the beginning of an array. To add …
Continue reading “Insert an element in specific index in JavaScript Array.”
Master Destructing Values in JavaScript
Learn how to destructure array and object properties into variables in JavaScript. Image from Unsplash The destructing syntax allows us to extract multiple values based on the property name from objects or arrays. // Destructing arrayvar num = [1,2,3,4,5]; var [a, b] = num; console.log(a, b); //1,2 // Destructing Object var obj = { name : …