Search results for "javascript"


How to parse cookies in javascript?

on September 6, 2021 🔥 80 views

In the browser cookies is store in string format containing key-value pairs. So, how to parse a browser Cookie string and return an object of all cookie name-value pairs? separate each key-value pair using String.prototype.split(‘;’) Use Array.prototype.map() and String.prototype.split(‘=’) to separate keys from values in each pair. Use Array.prototype.reduce() and decodeURIComponent() to create an object […]

snippets

How to use for loops to break out early in javascript?

on September 3, 2021 🔥 101 views

for loop in modern JavaScript is rarely talked about although it’s only useful in asynchronous operation scenarios. But what breaking out early consider the following example: Matching two array const smallArray = [0, 2]; const largeArray = Array.from({ length: 1000 }, (_, i) => i); const areEqual = (a, b) => { let result = […]

snippets

How to create a cookie using JavaScript?

on September 3, 2021 🔥 101 views

The simplest way to create a cookie is to assign a string value to the document.cookie object, for example- document.cookie = “key1 = value1; key2 = value2; expires = date”; // Example var now = new Date(); now.setTime(now.getTime() + 1 * 3600 * 1000); //set cookies to expire in 1 hour document.cookie = `${key} = […]

snippets

How to write a callback function in javascript?

on September 2, 2021 🔥 71 views

A callback function is a function that is passed to another function as an argument and is executed after some operation has been completed. for example of a simple callback function that logs to the console after some operations have been completed. function extendArray(arr, callback) { arr.push(100); // then execute the callback function that was […]

snippets

Answer for replaceAll is not a function JavaScript Error

on May 20, 2021 🔥 0 views

You can do it via regular expression: use the /g (“match globally”) modifier with a regular expression argument to replace if you are assigning a RegExp directly const a = “[email protected]”; a = a.replace(/xxxx-/g, “”); if you want to pass RegExp with some variable const a = “[email protected]”; const code = ‘xxxx’; const key = […]

discussion

replaceAll is not a function JavaScript Error

on May 20, 2021 🔥 0 views

I need an alternative of replaceAll method, as it was added in ES2021/ES12. const a = “[email protected]”; a = a.replace(“xxxx-“, “”); console.log(a); output // Actual [email protected] // Required [email protected]

discussion

What Is A Currying Function In Javascript?

on October 18, 2020 🔥 80910 views

In this tutorial, we will see What Is A Currying Function In Javascript. Currying is an alteration of functions that turns a function from callable as f(a, b, c) into callable as f(a)(b)(c). Currying Function In Javascript A currying function is a function that takes multiple arguments and turns it into a sequence of functions […]

post

Answer for Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

on October 15, 2020 🔥 0 views

You can run the following command in terminal to increase the heap memory. export NODE_OPTIONS=”–max-old-space-size=8192″

discussion

Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

on October 14, 2020 🔥 0 views

Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory I am getting this below error although I have a total of 4000 Unit Test Cases (test suits) and my test command is ng test –codeCoverage=true –progress=true –source-map=true   ERROR <— Last few GCs —> [17161:0x3436ed0] 77543 ms: Mark-sweep 1339.8 (1441.9) -> […]

discussion

Best Device Orientation API In Web Using Javascript

on September 28, 2020 🔥 87287 views

In this tutorial, we see the hidden gem that is Detecting device orientation in Web Using Javascript. you need to make sure your browser supports it. You can easily check caniuse.com. Code & Demo Works Better in Mobile Detecting device orientation It allows a device to detect its physical orientation with respect to gravity. If […]

post
1 2 3 11