Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 33 of 534
JavaScript Program to Check if a Given Matrix is Sparse or Not
To check if a given matrix is sparse or not, we will be discussing two different approaches, their complexities, and example codes. A sparse matrix is a special type of matrix in which the number of zeroes is strictly more than half of the total number of elements present in the given matrix. In this article we are having a 2D matrix, our task is to write a JavaScript program to check if a given matrix is sparse or not. Users must be familiar with conditional statement, nested for loop and javascript methods. Example Input: Matrix: [[1, ...
Read MoreHow to Get Last Day of Previous Month from Date in Moment.JS?
When working with dates in JavaScript, it's common to need specific dates for calculations or validations. One such situation is determining the last day of the previous month from a given date. In this article, we'll learn how to get the last day of the previous month using Moment.js. Prerequisite Moment.js: Moment.js is a popular JavaScript library used to parse, validate, manipulate, and display dates and times in JavaScript. You can install Moment.js in your project via npm: npm install moment Approaches to Get Last Day of Previous Month Below are two ...
Read MoreDetect Whether a Device is iOS or Not Using JavaScript
JavaScript is a high-level, interpreted programming language that is widely used for developing dynamic and interactive web applications. Its versatility and ease of use have made it one of the most popular programming languages in the world. In this tutorial, we'll explore how to use JavaScript to detect whether a device is running iOS or not. Knowing the type of device your users are accessing your web application from is crucial as a software developer. This information can be used to provide a better user experience or to customize the layout and functionality of your web application. In this ...
Read MoreJavaScript Program for the Last duplicate element in a Sorted Array
In this article, we are going to explore a JavaScript program that works with a sorted array containing duplicate elements. The task is to traverse the array using a loop and identify both the index of the last duplicate element and the duplicate number. Introduction to Problem In the given problem we have to find the last duplicate element in a sorted array. Duplicate means the number is present more than one time. Example − Input arr[] = {1, 2, 2, 3, 5, 5, 6, 7} Output Last index: 5 Last duplicate ...
Read MoreJavaScript Program for Finding Intersection Point of Two Linked Lists
In this tutorial, we will discuss two approaches to finding the intersection point of two linked lists in JavaScript. The first approach uses nested loops, and the second approach uses the difference of nodes technique which works in linear time. We will be given two linked lists that may intersect at some point. The intersection point is where both lists share the same node reference (not just the same value). After the intersection point, all subsequent nodes are identical in both lists. Problem Statement Given two linked lists, we need to find the node where they intersect. ...
Read MoreJavaScript Program to Find a triplet that sum to a given value
In this article, we will learn to find three numbers in an array that add up to a given sum value using JavaScript. We are going to write a JavaScript program to find a triplet that sums up a given value. This program will make use of nested loops to iterate over the input array and check for the existence of a triplet with a sum equal to the given value. We'll present two different approaches and analyze their implementations. Sorting and Two-Pointer Technique The first approach uses sorting and the two-pointer technique to solve the problem efficiently. ...
Read MoreHow to Filter Object by Keys in Lodash?
Sometimes while working with objects in JavaScript we want to filter objects based on keys. We can easily do this by using Lodash, a popular JavaScript library that provides several inbuilt functions to achieve this easily. In this article, we are going to discuss how we can Filter Objects by Keys using Lodash. Prerequisite Lodash: Lodash is a popular JavaScript library used to deal with a variety of functions such as arrays, objects, strings, and more. Install Lodash We can install the Lodash library in the project by adding it via CDN ...
Read MoreHow to Filter Object by Values in Lodash?
Sometimes we are given an object and we want to extract only the key-value pairs that meet certain criteria. In this article, we are going to discuss how we can filter objects by values in Lodash. Prerequisite Lodash: Lodash is a popular JavaScript library used to deal with a variety of functions such as arrays, objects, strings, and more. Install Lodash We can install the Lodash library in the project by adding it via CDN or npm using the following command: npm install lodash Approaches to Filter Object ...
Read MoreHow to Convert JavaScript Class to JSON in JavaScript?
JavaScript classes serve as blueprints for creating objects with properties and methods. When working with APIs or data storage, you often need to convert class instances to JSON format for serialization. This article demonstrates several approaches to convert JavaScript classes to JSON with practical examples. Approaches to Convert JavaScript Class to JSON Using JSON.stringify() Method Adding a Custom toJSON() Method Using Object.assign() Method Using Custom Serializer Using JSON.stringify() Method JSON.stringify() is the most straightforward method to convert a class ...
Read MoreHow to Run cmd.exe with parameters from JavaScript?
Running cmd.exe with parameters from JavaScript typically involves using Node.js because standard JavaScript running in the browser does not have access to the system's command line for security reasons. With Node.js, you can use the child_process module to execute cmd.exe or any command with parameters. Approaches to Run cmd.exe with Parameters Using Node.js to Run cmd.exe with Parameters Passing Parameters Dynamically Using Spawn for Advanced Scenarios Using Node.js to Run cmd.exe with Parameters The exec function from the child_process module is the simplest ...
Read More