Articles on Trending Technologies

Technical articles with clear explanations and examples

How to write shorthand for document.getElementById() method in JavaScript?

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

The document.getElementById() method allows us to access any HTML element using its id in JavaScript. Every webpage can contain only a single HTML element with a single id. You can use the below example code to access any HTML element using its id: let element = document.getElementById('id'); In the above code, we used the getElementById() method of the document object and passed the id as a parameter. Now, if we require to access multiple elements using their id, it is not a good idea to repeatedly type document.getElementById(), but we can create a ...

Read More

Remove json element - JavaScript?

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

In JavaScript, you can remove elements from JSON objects or arrays using different methods. This article demonstrates how to remove properties from JSON objects and elements from JSON arrays. Sample JSON Data Let's work with the following JSON array containing customer information: var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", ...

Read More

How to find capitalized words and add a character before that in a given sentence using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 229 Views

When working with strings that contain capitalized words, you might need to insert a character (like a comma) before each capital letter. This is useful for parsing concatenated sentences or formatting text data. Problem Statement Given a string with capitalized words, we want to add a comma before each capital letter that appears after another character: const str = "Connecting to server Connection has been successful We found result"; The goal is to transform this into: "Connecting to server, Connection has been successful, We found result" Solution Using Regular Expression We can ...

Read More

Deviations in two JavaScript arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 237 Views

We have two arrays of numbers and need to find elements that exist in one array but not in both. This is called finding the symmetric difference or deviation between arrays. const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34]; We need to write a JavaScript function that takes two arrays and returns elements that are not common to both arrays. Using indexOf() Method The basic approach uses indexOf() to check if elements exist in the other array: const arr1 ...

Read More

ES6 Default Parameters in nested objects – JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 631 Views

ES6 allows you to set default parameters for nested objects using destructuring assignment. This feature helps handle cases where nested properties might be undefined or missing. Syntax function myFunction({ outerKey: { innerProperty = defaultValue, anotherProperty = anotherDefault } = {} } = {}) { // Function body } Example Here's how to implement default parameters in nested objects: function ...

Read More

Convert JSON to another JSON format with recursion JavaScript

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

Suppose, we have the following JSON object − const obj = { "context": { "device": { "localeCountryCode": "AX", "datetime": "3047-09-29T07:09:52.498Z" }, "currentLocation": { "country": "KM", ...

Read More

Beautiful Arrangement of Numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 427 Views

A beautiful arrangement is a permutation of numbers from 1 to num where each position satisfies specific divisibility rules. This problem involves finding all valid arrangements using backtracking. Definition For an array with num integers from 1 to num, a beautiful arrangement requires that for each position i (1-indexed): The number at position i is divisible by i, OR i is divisible by the number at position i Problem Statement Write a JavaScript function that takes a number and returns the count of all possible ...

Read More

Limiting duplicate character occurrence to once in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 237 Views

In JavaScript, removing duplicate characters while maintaining lexicographical order requires a strategic approach. This problem asks us to keep only one occurrence of each character, choosing positions that result in the lexicographically smallest string. Problem Statement We need to write a JavaScript function that takes a string and returns a new string where each character appears only once. The key constraint is that the result must be lexicographically smallest among all possible combinations. For example, with input 'cbacdcbc', the output should be 'acdb'. Understanding the Algorithm The solution uses a greedy approach: ...

Read More

How to create Covid19 Country wise status project using REST API?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 624 Views

Before creating the project, we will first discuss REST API. REST is a software architecture style and a collection of standards that helps make online services. Representational State Transfer is the full name of REST. Application programming interfaces (API) allow communication between two or more computer programmes. It is a software interface that gives other software programmes a service. The user must follow the rules known as a REST API based on the HTTP (Hypertext Transfer Protocol) to access web services. Conventional HTTP methods like GET, POST, PUT, and DELETE access and modify resources like data objects in a ...

Read More

JavaScript Get English count number

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 258 Views

We are required to write a JavaScript function that takes in a number and returns an English ordinal number for it (1st, 2nd, 3rd, 4th, etc.). Example 3 returns 3rd 21 returns 21st 102 returns 102nd How Ordinal Numbers Work English ordinal numbers follow these rules: Numbers ending in 1: add "st" (1st, 21st, 31st) — except 11th Numbers ending in 2: add "nd" (2nd, 22nd, 32nd) — except 12th Numbers ending in 3: add "rd" (3rd, 23rd, 33rd) — except 13th All others: add "th" (4th, 5th, 6th, 7th, 8th, 9th, ...

Read More
Showing 16281–16290 of 61,297 articles
Advertisements