Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 241 of 534
How to iterate json array - JavaScript?
In JavaScript, iterating over JSON arrays is a common task when working with data from APIs or configuration files. A JSON array is an ordered list of values that can contain strings, numbers, booleans, objects, or other arrays. This article demonstrates various methods to iterate through JSON arrays in JavaScript, from traditional loops to modern ES6+ approaches. Understanding JSON Arrays JSON arrays are ordered collections of values enclosed in square brackets. Each element is separated by commas and can be accessed using numeric indices. Syntax [ { ...
Read MoreAccessing and returning nested array value - JavaScript?
Each value in an array is referred to as an element, and each element has a certain numerical location in the array, which is referred to as its index. Nested Arrays, a feature of JavaScript, allow us to create arrays inside arrays. One or more arrays can be used as the elements of nested arrays. Although the term may be a little unclear, as we look further, it is actually rather fascinating. Understanding Nested Arrays In JavaScript, a nested array is described as an Array (outer array) inside another array (inner array). One or more inner arrays ...
Read MoreSetting a default variable value to undefined in a function - JavaScript?
The task we are going to perform in this article is setting a default variable value to undefined in a function. Before we jump into the article, let's understand what are functions in JavaScript. One of the core components of JavaScript are functions. In JavaScript, a function is comparable to a procedure-a collection of statements that carry out an action or compute a value. However, in order for a process to be considered a function, it must accept an input and produce an output with an evident connection between the input and the result. Let's see how to ...
Read MoreReturn correct value from recursive indexOf in JavaScript?
A computer pattern or idea called recursion is present in many programming languages, including JavaScript. It is a feature used to build a function that repeatedly calls itself, but with a smaller input each time, until the intended outcome of the code is realized. In this article, we will return the correct value from a recursive indexOf() function in JavaScript. Let's dive into the article for a better understanding. Understanding Recursive indexOf Implementation The position of the first occurrence of a value in a string or array is returned by the indexOf() method. -1 is returned by ...
Read MoreHow to handle ESC keydown on JavaScript popup window?
When we press the escape key, the event generated is detected using the keyup and keydown event handlers. When the escape key is pushed on the keyboard, the event handler runs across the page. Let's dive into the article for getting better understanding on handling ESC keydown on JavaScript popup window. Using keydown Event When a key is pushed, the keydown event is triggered. The keydown event is called for all keys, regardless of whether they generate a character value, in contrast to the deprecated keypress event. While keypress shows which character was entered, keydown and keyup events ...
Read MoreDo JavaScript arrays have an equivalent of Python’s \"if a in list\"?
JavaScript provides the includes() method as the direct equivalent of Python's if item in list syntax. This method returns true if the element exists in the array, otherwise false. In Python, you check membership using: # Python syntax if "apple" in fruits: print("Found!") JavaScript achieves the same result with the includes() method, which is supported in all modern browsers and provides a clean, readable solution. Syntax array.includes(searchElement, fromIndex) Parameters searchElement − The element to search for in the array fromIndex (optional) − The position ...
Read MoreHow to remove all blank objects from an Object in JavaScript?
In JavaScript, removing blank or empty values from an object is a common task when cleaning up data. This article explores different methods to filter out empty strings, null values, or undefined properties from objects. Sample Object with Empty Values Let's work with an object containing empty values that we want to remove: const details = { name: 'John', ...
Read MoreCapitalize a word and replace spaces with underscore - JavaScript?
In JavaScript, you can capitalize words and replace spaces with underscores using various string methods. This transformation is commonly needed for creating identifiers, constants, or formatted text. let input = "tutorials point"; console.log("Input:", input); // Expected output: "Tutorials_Point" Input: tutorials point Let's explore different methods to achieve this transformation in JavaScript. Using replace() Method The replace() method searches for a specified pattern in a string and replaces it with a new value. It accepts regular expressions for complex pattern matching. Syntax string.replace(searchValue, newValue) Example 1: Basic ...
Read MoreHow to format date value in JavaScript?
JavaScript provides several methods to format dates according to your requirements. The built-in Date object offers various formatting options, from simple string conversion to locale-specific formatting. Using toLocaleDateString() Method The toLocaleDateString() method formats dates according to locale and custom options, providing flexible date formatting. Example Here's how to format dates with custom options using toLocaleDateString(): var options = { year: 'numeric', ...
Read MoreHow do I change a tag\'s inner HTML based on their order in JavaScript?
In JavaScript, you can change a tag's innerHTML based on their order using document.querySelectorAll() or getElementsByClassName(). These methods return collections of elements that you can iterate through and modify based on their position in the DOM. This technique is useful for numbering elements, adding order-based content, or applying different innerHTML to similar elements based on their sequence. Using document.querySelectorAll() The querySelectorAll() method returns a static NodeList containing all elements that match the specified CSS selector(s). Syntax document.querySelectorAll(selectors) Example 1: Basic Order Assignment Here's how to change innerHTML based on element order ...
Read More