AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 455 of 840

Deleting the duplicate strings based on the ending characters - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

We are required to write a JavaScript function that takes in an array of strings and deletes each one of the two strings that ends with the same character. For example, if the actual array is: const arr = ['Radar', 'Cat', 'Dog', 'Car', 'Hat']; Then we have to delete duplicates and keep only one string ending with the same character. In this case, 'Cat', 'Car', and 'Hat' all end with 't', 'r', and 't' respectively, so we need to remove duplicates based on the last character. How It Works The algorithm uses a ...

Read More

How to create a weight converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 527 Views

Creating a weight converter with HTML and JavaScript involves building a simple form that takes weight input in one unit and converts it to another unit in real-time. This tutorial demonstrates how to create a kilogram to gram converter. HTML Structure The HTML provides the basic structure with an input field for kilograms and a display area for the converted grams: body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } input, span{ ...

Read More

Function borrowing in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 482 Views

Function borrowing in JavaScript allows objects to use methods from other objects without inheriting from them. This is achieved using call(), apply(), and bind() methods. Understanding Function Borrowing When an object doesn't have a particular method but needs to use it, it can "borrow" that method from another object. The borrowed method executes in the context of the borrowing object using the this keyword. Using call() Method The call() method invokes a function with a specific this context and individual arguments. Function Borrowing with call() ...

Read More

Transform nested array into normal array with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 363 Views

In JavaScript, nested arrays can be flattened into a single-level array using several methods. The most common approach is the flat() method, which removes one level of nesting by default. What is Array Flattening? Array flattening transforms a nested array structure into a single-dimensional array. For example, converting [[1, 2], [3, 4]] into [1, 2, 3, 4]. Using flat() Method The flat() method creates a new array with sub-array elements flattened into it. Here's how to flatten a nested array containing objects: const arrayObject = [ [ ...

Read More

Filtering out primes from an array - JavaScript

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

We are required to write a JavaScript function that takes in an array of numbers and returns a new filtered array that does not contain any prime number. Problem Statement Given an array of numbers, we need to filter out all prime numbers and return only the composite and non-prime numbers. const arr = [34, 56, 3, 56, 4, 343, 68, 56, 34, 87, 8, 45, 34]; Understanding Prime Numbers A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Numbers like 2, ...

Read More

How to create a temperature converter with HTML and JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 938 Views

To create a temperature converter with HTML and JavaScript, you need to combine form elements with JavaScript functions to perform real-time temperature conversions. Complete Temperature Converter Example body{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; } .converter-container { background: #f8f9fa; border-radius: ...

Read More

Disabling arrow key in text area using JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 404 Views

You can disable arrow key navigation in a text area using JavaScript by intercepting keydown events and preventing their default behavior. This technique is useful when you want to restrict user interaction or create custom navigation controls. Understanding Arrow Key Codes Arrow keys have specific key codes that we can detect: Left Arrow: 37 Up Arrow: 38 Right Arrow: 39 Down Arrow: 40 Complete Example Disable Arrow Keys in Textarea ...

Read More

How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 621 Views

In JavaScript, arrays can contain null or undefined values. To display only non-null and non-undefined values, you need to check each element before processing it. Sample Array with Mixed Values Let's start with an array containing valid strings, null, and undefined values: var firstName = ["John", null, "Mike", "David", "Bob", undefined]; console.log("Original array:", firstName); Original array: [ 'John', null, 'Mike', 'David', 'Bob', undefined ] Method 1: Using for Loop with != undefined This approach checks if each element is not undefined. Since null != undefined evaluates to true, this will ...

Read More

Split keys and values into separate objects - JavaScript

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

In JavaScript, you often need to transform an object into an array of objects where each key-value pair becomes a separate object. This is useful for data processing, API responses, and working with libraries that expect array formats. Problem Statement Suppose we have an object like this: const dataset = { "diamonds": 77, "gold-bars": 28, "exciting-stuff": 52, "oil": 51, "sports-cars": 7, "bitcoins": 40 }; We need to write a JavaScript function that takes this object and returns an array of objects with ...

Read More

How to create a length converter with HTML and JavaScript?

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

To create a length converter with HTML and JavaScript, you'll need to combine HTML form elements with JavaScript functions to handle the conversion logic. This tutorial demonstrates building a simple kilometer-to-meter converter. HTML Structure The converter uses an input field for kilometers and displays the converted meters value. The oninput and onchange events trigger the conversion function automatically as you type. Complete Example body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; ...

Read More
Showing 4541–4550 of 8,392 articles
« Prev 1 453 454 455 456 457 840 Next »
Advertisements