A Method To Find a Value that is Present Or Not in An Array of Objects in Javascript

Scenario: If we want to check whether any particular values are present in an array of objects and to do some actions according to that. Then we can use the following code: Here the data is from the pricing schedule which is basically an array of jects so here we are finding the price of… Continue reading A Method To Find a Value that is Present Or Not in An Array of Objects in Javascript

How to disable and enable the scroll in website(Java Script)

In this section we can see how we can disable and enable scrolling option in an ecommerce website using javascript function. First of all we have to set up a block of code in the respective page. // PREVENT DEFAULT HANDLERfunction preventDefault(e) {  e = e || window.event;  if (e.preventDefault) {    e.preventDefault();  }  e.returnValue =… Continue reading How to disable and enable the scroll in website(Java Script)

Resolve SyntaxError: Invalid shorthand property initializer in JavaScript

SyntaxError: Invalid shorthand property initializer error comes when we use the equals operator rather than a colon to separate key-values(properties) in the object. To resolve this issue, we need to use a colon(:) rather than the equals operator(=) between the key and values of an object. Let’s see with the help of an example: Notice… Continue reading Resolve SyntaxError: Invalid shorthand property initializer in JavaScript

Code for generating Unique ID Using timestamp

We can generate unique IDs using the following Java script code. We can use this code for requirement which needs a unique value to be generated every time or when a conditions satifies. And there are Random ID generating code are available but here we are using current date and time values to generate unique… Continue reading Code for generating Unique ID Using timestamp

Array Merge/ Combine in JS

Merge without removing duplicate elements -> Using concat() Method: The concat() method accepts arrays as arguments and returns the merged array. // with elements of nums1 and returns the // combined array – combinedSum arraylet combinedNums = nums1.concat(nums2, nums3);// More readable formlet combinedNums = [].concat(nums1, nums2, nums3); -> Using spread operator: Spread operator spreads the value of the array into… Continue reading Array Merge/ Combine in JS

Map in JavaScript

In JavaScript, a Map is a built-in object that allows you to store key-value pairs, similar to an object. However, a Map offers some additional functionality that makes it useful in certain situations. Here’s an example of creating a Map: To add a key-value pair to the Map, you can use the set() method: You… Continue reading Map in JavaScript

Set in JavaScript

In JavaScript, a Set is a collection of unique values of any type, which means that each value can occur only once in the Set. It can be used to store a collection of values without any duplication. To create a Set in JavaScript, we use the Set() constructor or the Set literal notation by… Continue reading Set in JavaScript

Extracting a pattern from a string using javascript

Need to get the Prospect ID from the email body. But the usual split() method doesn’t work all the time. So switched to match() method, which returns the first occurrence of this pattern in the string. Example: This is the pattern , [Prospect:CUS234563]. Want to extract the “CUS234563” only. we first define a regular expression… Continue reading Extracting a pattern from a string using javascript

How to display a date object as a date value in another timezone

In Javascript, the date object does not store any specific timezone value. The time is stored in the value of the local timezone relative to GMT(Greenwich Mean Time). If we print the time object, we can see that the time is represented as a value with a sign and offset from the UTC(Coordinated Universal Time)… Continue reading How to display a date object as a date value in another timezone

Different Timezone Abbreviations and Time Offset values for Date Object Creation

Following is a list of country codes, their timezone identifiers, the timezone offset in each of these regions with respect to UTC, and the standard Timezone abbreviations for each location. These are very useful when you want to convert the time object value in a specific time zone to a time object value in a… Continue reading Different Timezone Abbreviations and Time Offset values for Date Object Creation