Articles on Trending Technologies

Technical articles with clear explanations and examples

How to search for a string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 324 Views

JavaScript provides several methods to search for strings. The most common approaches are search(), indexOf(), includes(), and match(). Using search() Method The search() method returns the index of the first match or -1 if not found. It supports regular expressions. String Search Example The spring season is about to come. SEARCH FOR 'spring' ...

Read More

Parsing array of objects inside an object using maps or forEach using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 849 Views

When working with nested data structures in JavaScript, you often need to parse arrays of objects within objects. This can be efficiently done using map() or forEach() methods to iterate through the data and extract the information you need. Understanding the Data Structure Consider a JSON object containing store data with nested arrays of items: let json = { storeData: [ { items: [ ...

Read More

How to convert an array into a complex array JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 385 Views

In JavaScript, converting a flat array into a complex nested array structure involves grouping elements based on specific conditions. A common use case is splitting an array into subarrays when the sum of consecutive elements exceeds a given threshold. Let's say we need to write a function that takes an array of numbers and a number n, where n is the maximum sum allowed for each subarray. The function should break the array into subarrays whenever the sum of consecutive elements would exceed n. Example Problem Given an array and a threshold value, we want to create ...

Read More

In JavaScript, can be use a new line in console.log?

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

Yes, you can use newlines in console.log() using the escape character. This creates line breaks in console output. Basic Newline Usage console.log("First lineSecond lineThird line"); First line Second line Third line Multiple Ways to Add Newlines There are several approaches to include newlines in console output: // Method 1: Using escape character console.log("HelloWorld"); // Method 2: Multiple console.log() calls console.log("Hello"); console.log("World"); // Method 3: Template literals with actual line breaks console.log(`Hello World`); // Method 4: Combining text with newlines console.log("Name: JohnAge: 25City: New York"); ...

Read More

Calculating resistance of n devices - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 300 Views

In Physics, the equivalent resistance of resistors varies based on their connection type. When resistors are connected in series, their resistances add directly: R_series = R1 + R2 + R3 For parallel connections, we use the reciprocal formula: 1/R_parallel = (1/R1) + (1/R2) + (1/R3) We need to create a JavaScript function that calculates equivalent resistance for any number of resistors in either series or parallel configuration. Series Connection Implementation For series resistors, we simply sum all resistance values: const calculateSeries = (...resistors) => { ...

Read More

What records are present in JavaScript cookies?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 266 Views

Your server sends some data to the visitor's browser in the form of a cookie. The browser may accept the cookie. If it does, it is stored as a plain text record on the visitor's hard drive. Now, when the visitor arrives at another page on your site, the browser sends the same cookie to the server for retrieval. Once retrieved, your server knows/remembers what was stored earlier. Cookies are a plain text data record of 5 variable-length fields − Cookie Fields Structure Name = Value − Cookies are set and retrieved in ...

Read More

How can I escape HTML special chars in JavaScript?

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

HTML contains special characters such as '', '/' and many more such as single and double quotes. These special characters are used for HTML tags, such as '' are used to close HTML tags. This tutorial teaches us to escape HTML special characters in JavaScript. Now, the question is what if we want to use these characters inside the HTML content? If we use special characters normally in HTML content, it considers them as opening or closing HTML tags and produces an unknown error. For example, we need to render the below string to the browser: ...

Read More

Is there any way of moving to HTML 5 and still promise multi browser compatibility?

Arjun Thakur
Arjun Thakur
Updated on 15-Mar-2026 268 Views

Yes, you can migrate to HTML5 while maintaining multi-browser compatibility by following a progressive enhancement approach. Key Strategies for HTML5 Compatibility Move to the HTML5 doctype: Use or new semantic elements like , , For multimedia, use newer HTML5 tags like or with fallbacks to the older tag HTML5 form controls have built-in backward compatibility. For example, works the same as in browsers that don't support it Example: Progressive Enhancement with ...

Read More

How to send a cross-document message with HTML?

Nancy Den
Nancy Den
Updated on 15-Mar-2026 255 Views

Cross-document messaging allows secure communication between different browsing contexts (windows, iframes, or tabs) using the postMessage() API, even when they have different origins. Syntax targetWindow.postMessage(message, targetOrigin); Parameters message − The data to send (string, object, or any serializable value) targetOrigin − The origin URL of the target window (use "*" for any origin, but specify for security) Example: Sending Message from Parent to Iframe Parent window HTML: Send Message to Iframe ...

Read More
Showing 17281–17290 of 61,297 articles
Advertisements