Articles on Trending Technologies

Technical articles with clear explanations and examples

Tutorix - AI Tutor

Setting property in an empty object using for loop in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 539 Views

In JavaScript, you can populate an empty object with properties using various loop methods. The most common approaches are the for...in loop and the for...of loop with Object.entries(). Using for...in Loop The for...in loop iterates over all enumerable properties of an object, making it ideal for copying properties from one object to another. Setting Properties with for...in Loop Setting Properties in Empty Object Populate ...

Read More

JavaScript Compare two sentences word by word and return if they are substring of each other

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 249 Views

The idea here is to take two strings as input and return true if one string is a substring of the other, otherwise return false. For example: isSubstr('hello', 'hello world') // true isSubstr('can I use', 'I us') // true isSubstr('can', 'no we are') // false In the function, we check which string is longer and then verify if the shorter string exists as a substring within the longer one. Syntax const isSubstr = (first, second) => { if (first.length > second.length) { ...

Read More

How can I filter JSON data with multiple objects?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 17K+ Views

To filter JSON data with multiple objects, you can use the filter() method along with comparison operators. This allows you to extract specific objects based on criteria. Syntax array.filter(callback(element, index, array)) Example: Filter by Single Property const jsonObject = [ { studentId: 101, studentName: "David" }, { studentId: 102, ...

Read More

Checking semiprime numbers - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 494 Views

We are required to write a JavaScript function that takes in a number and determines if the provided number is a semiprime or not. What is a Semiprime? A semiprime number is a special type of composite number that is the product of exactly two prime numbers (not necessarily distinct). For example: 6 = 2 × 3 (product of two distinct primes) 15 = 3 × 5 (product of two distinct primes) 10 = 2 × 5 (product of two distinct primes) 4 = 2 × 2 (square of a prime) 9 = 3 × 3 ...

Read More

How to convert an array into JavaScript string?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 9K+ Views

An array is the most popular and adaptable data structure you might employ in your regular programming. Converting an array into a JavaScript String can be done using several predefined methods and techniques. Using the toString() Method Using the join() Method Using JSON.stringify() Method Using Type Coercion Using the toString() Method The toString() method is a built-in JavaScript function that converts array elements into a comma-separated string. It's the simplest way to convert an array to string format. ...

Read More

How can we assign a function to a variable in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 27K+ Views

In this tutorial, we will learn to assign a function to a variable in JavaScript. Functions are reusable code blocks that can be stored in variables as expressions. There are two main ways to achieve this: using anonymous functions and arrow functions. Most JavaScript programmers are familiar with named functions, which follow this syntax: function function_name() { // function body } However, when we want to assign a function to a variable as an expression, we have two different approaches: Creating Anonymous Functions ...

Read More

What is the usage of oninput event in JavaScript?

Sai Nath
Sai Nath
Updated on 15-Mar-2026 532 Views

The oninput event occurs whenever the value of an input element changes. Unlike onchange, which fires only when the element loses focus, oninput triggers immediately as the user types, making it ideal for real-time validation and live search functionality. Syntax // HTML attribute // JavaScript property element.oninput = function() { /* code */ }; // Event listener element.addEventListener('input', function() { /* code */ }); Basic Example oninput Example Type something below: ...

Read More

How to set an image as the list-item marker with JavaScript?

Monica Mona
Monica Mona
Updated on 15-Mar-2026 264 Views

To set an image as the marker in list items, use the listStyleImage property in JavaScript. This property allows you to replace default list markers (bullets or numbers) with custom images. Syntax element.style.listStyleImage = "url('image-path')"; Example The following example demonstrates how to set a custom image as the list-item marker: First Item Second Item Third Item ...

Read More

Websocket for binary transfer of data & decode with HTML5

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 1K+ Views

WebSockets can handle binary data transfer using base64 encoding/decoding. Modern browsers provide built-in methods window.btoa() for encoding and window.atob() for decoding base64 data. Base64 Encoding for Binary Transfer When transferring binary data through WebSockets, encode it as base64 on the client side before sending: // Create WebSocket connection const socket = new WebSocket('ws://localhost:8080'); // Convert ...

Read More

Remove elements from a Dictionary using Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 25K+ Views

In JavaScript, there are multiple ways to remove elements from dictionary-like structures. This depends on whether you're working with plain objects, custom dictionary classes, or ES6 Maps. Using delete Operator with Objects For plain JavaScript objects acting as dictionaries, use the delete operator: const dict = { key1: "value1", key2: "value2", key3: "value3" }; console.log("Before deletion:", dict); delete dict.key2; console.log("After deletion:", dict); console.log("key2 exists:", "key2" in dict); Before deletion: { key1: 'value1', key2: 'value2', key3: 'value3' } After ...

Read More
Showing 17981–17990 of 61,298 articles
Advertisements