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
Found 5,340 articles
Adding an element at a given position of the array in Javascript
In this article, we are going to learn how to add an element at a given position of the array in JavaScript. An array is a special variable that can hold more than one value. JavaScript provides several ways to insert an element at a specific index, including the built-in splice() method and the spread operator approach. Syntax The most common way to insert an element at a given position is using the splice() method − array.splice(index, 0, element); Here, index is the position where the element should be inserted, 0 means no elements ...
Read MoreWhich one is the Python module to obfuscate javascript?
You can use the jsmin module to minimize and obfuscate JavaScript code using Python. Minification removes whitespace, comments, and unnecessary characters from JavaScript files, reducing file size without changing functionality. Installing jsmin Install jsmin using pip − $ pip install jsmin Syntax Following is the basic syntax for using jsmin in Python − from jsmin import jsmin minified_code = jsmin(javascript_string) The jsmin() function takes a JavaScript source string as input and returns the minified version as a string. Minifying a JavaScript File To use jsmin in ...
Read MoreHow to check whether image is loaded or not?
To check whether an image is loaded in JavaScript, you can use event listeners or the complete property. This is useful for handling loading states, showing fallbacks, or performing actions after images load. Common Image Loading Issues Images may fail to load due to: Large file size causing slow loading Poor network connectivity Incorrect image URL or path Server errors or missing files Available Methods onload event − Triggers when the image loads successfully onerror ...
Read MoreHow to share code between Node.js and the browser?
Sharing code between the backend and front end of a full-stack application can be a challenging task. However, it's essential for building maintainable and scalable applications. By sharing code, we can avoid code duplication, reduce development time, and maintain consistency across our applications. In this tutorial, we'll explore different techniques for sharing code between Node.js and the browser and learn how to choose the best approach for our project. Techniques for Sharing Code Between Node.js and the Browser Users can follow the approaches below to share code between Node.js and the browser: CommonJS Modules CommonJS ...
Read MoreHow to terminate a script in JavaScript?
The termination of the script means that it stops executing the JavaScript code. In some emergency cases, developers require to abort the execution of JavaScript code in the middle while the script is executing. Also, we can use the if-else statement to decide when to terminate the script execution and when to continue. Here, we will learn different ways to terminate the script midway. Use the Return Statement The return statement is used to terminate the execution of any code inside the function. Once we execute the return statement inside the function, the code written after the ...
Read MoreHow to check if the string contains only digits in JavaScript?
We may require to find the string, which contains only digits but not any other characters while developing. The easiest way to check can parse the numbers from the string and compare its length with the original string's length. If both are the same, that means the string contains only digits. Users can use the parseInt() method to parse the numbers from the string. However, in this tutorial, we will learn other methods to check if the string contains only digits in JavaScript. Using the for-loop and charCodeAt() Method We can iterate through the string using the ...
Read MoreJavaScript Program to Generate a matrix having sum of secondary diagonal equal to a perfect square
We will write a JavaScript program that generates a matrix with the sum of the secondary diagonal being a perfect square. Our program will use nested loops to traverse the matrix and calculate the sum of the secondary diagonal elements. We will then use the Math.sqrt() method to find the square root of the sum and check if it is a whole number. If it is, we will consider the sum to be a perfect square. Understanding Secondary Diagonal The secondary diagonal (also called anti-diagonal) consists of elements from the top-right to bottom-left corner. For a 3×3 matrix, ...
Read MoreHow to convert speech to text using JavaScript?
Overview To convert spoken words to text, we use the Web Speech API's SpeechRecognition component. The SpeechRecognition interface recognizes spoken audio and converts it to text. The spoken words are processed and displayed as text in HTML elements on the browser screen. Syntax The basic syntax for creating a speech recognition instance: let recognition = new webkitSpeechRecognition(); // or let recognition = new SpeechRecognition(); Note: webkitSpeechRecognition() is used for Chrome and Safari browsers, while SpeechRecognition() is the standard implementation for other browsers. Browser Compatibility Check Before implementing speech recognition, it's important ...
Read MoreImage Classification using JavaScript
Image classification is a machine learning technique that identifies and categorizes objects within digital images. When you upload a photo to Google Photos, for instance, it uses image classification to suggest locations, identify people, or tag objects automatically. We can use OpenCV to detect detailed information from images and make predictions. However, training models from scratch requires extensive datasets and computational resources. This tutorial demonstrates using ml5.js, a JavaScript library with pre-trained models that leverages browser GPU for efficient image classification. What is ml5.js? The ml5.js library provides various pre-trained machine learning models, making AI accessible to ...
Read MoreJavaScript Program for Find the smallest missing number
We are given a sorted array of distinct non-negative integers, here we have to find the smallest missing number. Hence in this tutorial, we will explore different methods to solve this problem and discuss their time complexities with various examples. Understanding the Problem The problem statement is quite simple. Given a sorted array of distinct non-negative integers, we need to find the smallest missing number in it. Let's take an example to understand the problem. Example Let's say that we have an array [1, 2, 4, 5, 6]. Here, We can see that there is a ...
Read More