Articles on Trending Technologies

Technical articles with clear explanations and examples

Returning the nth even number using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 656 Views

We are required to write a JavaScript function that takes in a number n and returns the nth even number in the sequence of natural numbers. Problem Given a positive integer n, find the nth even number. For example, the 1st even number is 2, the 2nd even number is 4, the 3rd even number is 6, and so on. Understanding the Pattern Even numbers follow a simple pattern: 2, 4, 6, 8, 10, 12... The nth even number can be calculated using the formula: n × 2. Example Implementation Here's how to implement ...

Read More

How to return HTML or build HTML using JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 19K+ Views

When building web applications, there are often times when you need to dynamically generate HTML on the client-side. This can be done using JavaScript, and there are different ways to go about it. In this article, we'll show you how to return HTML or build HTML using JavaScript. Method 1: Returning HTML from a Function One way to dynamically generate HTML is to return a string of HTML from a function. For example, let's say we have a function that generates a list item: Returning HTML from Functions ...

Read More

Does Google Crawl JavaScript with Body Content

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 576 Views

Historically, search engine crawlers like Googlebot could only read static HTML source code and could not scan and index content generated dynamically using JavaScript. This changed with the rise of JavaScript-rich websites and frameworks like Angular, React, and Vue.js, as well as single-page applications (SPAs) and progressive web applications (PWAs). Google has evolved its crawling technology to properly render web pages before indexing them. Although Google can now crawl and index most JavaScript content, they still recommend against relying solely on client-side solutions since JavaScript is "tough to process, and not all search engine crawlers can process it properly or ...

Read More

How to edit values of an object inside an array in a class - JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 313 Views

In JavaScript, you can edit values of objects inside an array within a class by using the this keyword. This allows you to reference and modify properties of objects stored in class arrays. Understanding the Structure When working with objects inside arrays in classes, each object can contain its own methods that modify its properties. The key is understanding how this refers to the current object context. Example Here's how to create a class with an array of objects and modify their values: class Employee { constructor() { ...

Read More

Checking for special type of Arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 213 Views

We are required to write a JavaScript function that takes in an array of literals and checks if elements are the same or not if read from front or back. Such arrays are also known by the name of palindrome arrays. Some examples of palindrome arrays are: const arr1 = ['a', 'b', 'c', 'b', 'a']; const arr2 = [4, 7, 7, 4]; const arr3 = [7, 7, 7, 7, 7, 7]; Method 1: Using a For Loop This approach compares elements from both ends moving towards the center: const arr = [1, ...

Read More

Is the second string a rotated version of the first string JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 212 Views

We are required to write a JavaScript function that takes in two strings, say str1 and str2. We are required to determine whether or not the second string is a rotated version of the first string. For example − If the input strings are − const str1 = 'abcde'; const str2 = 'cdeab'; Then the output should be true because str2 is indeed made by shifting 'ab' to the end of string in str1. Understanding String Rotation A string rotation means taking some characters from the beginning of a string and moving them ...

Read More

Difference between first and the second array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 249 Views

When working with arrays in JavaScript, you often need to find elements that exist in one array but not in another. This operation is commonly known as finding the "difference" between two arrays. We'll create a function that takes two arrays and returns all elements from the first array that don't exist in the second array. Example Here's how to implement this functionality: const arr1 = ['1', '2', '3', '4/2', '5/4', '6-2']; const arr2 = ['1', '2', '3', '5/4', '4/2', '6-1', '7/2', '8-2']; const differenceBetween = (arr1 = [], arr2 = []) => { ...

Read More

Returning array of natural numbers between a range in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 236 Views

We need to write a JavaScript function that takes an array of two numbers [a, b] (where a ≤ b) and returns an array containing all natural numbers within that range, including the endpoints. Problem Given a range specified by two numbers, we want to generate all natural numbers between them. Natural numbers are positive integers starting from 1. Using a For Loop The most straightforward approach uses a for loop to iterate through the range and build the result array: const range = [6, 10]; const naturalBetweenRange = ([lower, upper] = [1, ...

Read More

Filtering out numerals from string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 224 Views

We are required to write a JavaScript function that takes in a string, str, which contains a combination of alphabets, special characters and numbers. Our function should return a new string based on the input string that contains only the numbers present in the string str, maintaining their relative order. For example, if the input to the function is: const str = 'revd1fdfdfs2v34fd5gfgfd6gffg7ds'; Then the output should be: '1234567' Using for Loop and Type Coercion This approach iterates through each character and uses the unary plus operator (+) to ...

Read More

How to get the first non-null/undefined argument in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 4K+ Views

In JavaScript, there are often times when we need to find the first non-null/undefined argument in a function. This can be a tricky task, but luckily there are a few methods that can help us accomplish this. Using Array.prototype.find() One method that can be used to get the first non-null/undefined argument in JavaScript is the Array.prototype.find() method. This method returns the value of the first element in an array that passes a given test. In our case, we can use this method to find the first non-null/undefined argument by passing a test that checks if the argument is ...

Read More
Showing 16481–16490 of 61,297 articles
Advertisements