Make API call (POST Request) using JavaScript in browser’s debug console

const xhr = new XMLHttpRequest(); const url = “END_POINT”; const data = {};//Request Body xhr.open(“POST”, url, true); xhr.setRequestHeader(“Content-Type”, “application/json”); xhr.onreadystatechange = function () {     if (xhr.readyState === 4 && xhr.status === 200) {         console.log(xhr.responseText);     } }; xhr.send(data);

Create an HTML file using Vue.js via CDN

<!DOCTYPE html> <html lang=”en”> <head>     <meta charset=”utf-8″ />     <meta name=”viewport” content=”width=device-width,initial-scale=1.0″>     <script src=”https://unpkg.com/vue@3/dist/vue.global.js”></script>     <title>Title</title>     <style>     </style> </head> <body>     <div id=”app”>     </div> </body> <script>     const { createApp } = Vue;     const app = createApp({    … Continue reading Create an HTML file using Vue.js via CDN

Why Fetch Promise Doesn’t Reject on Error Responses

The problem If you’ve been using the fetch() function in the browser or modern versions of Node.js, you know that it returns a Promise. 1fetch(request).then((response) => { 2 // Handle the response. 3}) You also know that promises in JavaScript reject if there’s been an error while resolving them. But, for some obscure reason, the Promise returned from fetch() never rejects… Continue reading Why Fetch Promise Doesn’t Reject on Error Responses

Object.keys

Object.keys() returns an array whose elements are strings corresponding to the enumerable string-keyed property names found directly upon object. This is the same as iterating with a for…in loop, except that a for…in loop enumerates properties in the prototype chain as well. The order of the array returned by Object.keys() is the same as that… Continue reading Object.keys

Shallow copy and Deep copy

Shallow Copy When a reference variable is copied into a new reference variable using the assignment operator, a shallow copy of the referenced object is created. In simple words, a reference variable mainly stores the address of the object it refers to. When a new reference variable is assigned the value of the old reference… Continue reading Shallow copy and Deep copy

Parse XML to JSON without using any DOM or NetSuite functions

Following is a library/function to Parse XML data to JSON without using any DOM or NetSuite functions Library File :     const xml2json = {         parser: function (xmlcode, ignoretags = [], debug = false) {             xmlcode = xmlcode.replace(/s*/>/g, ‘/>’);          … Continue reading Parse XML to JSON without using any DOM or NetSuite functions

JavaScript — What’s new with ECMAScript® 2024 (ES15) — In Depth Guide

Discovering new functionality in programming languages is like the holidays or a birthday — it’s an exciting time filled with anticipation and the joy of exploring new gifts. With the proposed features of ES2024®, developers are on the brink of unwrapping a variety of enhancements that promise to make coding in JavaScript more efficient, readable, and… Continue reading JavaScript — What’s new with ECMAScript® 2024 (ES15) — In Depth Guide

Function to create a file name for exported Excel document

The requirement was to generate unique and valid file names for Microsoft Excel files. The name should contain the data title and date/time when the data was exported. Here is the code I used for creating the file names for Excel documents: function fileNameCreate(title: string): string {  // Remove invalid characters, replace spaces with underscore… Continue reading Function to create a file name for exported Excel document

Calculate total from an array of object contains similar items.

Function to find the total from an array of object if it contains similar items. var groupedByItem = arr.reduce(function (result, current) {    var item = current.Item;    if (!result[item]) {       result[item] = {          Type: current.Type,          Item: item,          TotalQuantity: 0       };    }    result[item].TotalQuantity += parseInt(current.Quantity);    return result;… Continue reading Calculate total from an array of object contains similar items.