Yaswanth Varma

Yaswanth Varma

307 Articles Published

Articles by Yaswanth Varma

Page 12 of 31

Remove property for all objects in array in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

Removing properties from all objects in an array is a common JavaScript task. You can accomplish this using either the delete operator (which mutates the original objects) or object destructuring with the rest operator (which creates new objects). A collection of key-value pairs constitutes an object in JavaScript. A key-value pair among them is referred to as an object property. Any data type, including Number, String, Array, Object, etc., can be used for both the keys and values of properties. Method 1: Using the delete Operator (Mutable) The delete operator removes both the property's value and the ...

Read More

Shortest syntax to assign properties from function call to an existing object in JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 172 Views

In JavaScript, you can quickly assign properties from a function call to an existing object using several concise syntaxes. This article explores the most efficient approaches to merge function-returned properties into existing objects. An object in JavaScript is a separate entity having properties and a type. JavaScript objects can have properties that specify their attributes. Using Spread Syntax (...) The spread syntax provides the shortest way to assign properties from a function call to an existing object. It expands an object's properties into a new object, effectively merging them. Syntax existingObject = { ...existingObject, ...

Read More

Is there any way to check if there is a null value in an object or array in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 9K+ Views

Null values can be tricky to work with in JavaScript, but they are an important part of the language. In this article, we will discuss various ways you can check if there is a null value in an object or array in JavaScript. The null values display that no object value is present. It is intentionally set to show that a variable has been declared but has not yet been given a value. The primitive value is undefined, which is an unintended absence of any object value, which is comparable to null, that contrasts with the former. This ...

Read More

How to compare two arrays when the key is a string - JavaScript

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

Comparing two arrays in JavaScript can be tricky when the key is a string. String comparisons are case-sensitive and require special handling to ensure proper results. Fortunately, there are several methods you can use to compare two arrays when the key is a string in JavaScript. In this article, we'll discuss how to effectively compare two arrays with strings as keys using various approaches such as map(), includes(), intersection logic, and filter(). Strings in JavaScript are used to store and modify text. A string in JavaScript is defined as zero or more characters enclosed in quotations. Data that ...

Read More

How to iterate json array - JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 7K+ Views

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 More

Add class name in different li by pure in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

Adding class names to different list items (li elements) is a common task in JavaScript DOM manipulation. This can be achieved using various methods like forEach() with classList.add(), CSS selectors, or DOM traversal properties. Let's explore different approaches to add class names to list items using pure JavaScript. Method 1: Using forEach() with classList.add() The forEach() method executes a function for each array element, while classList.add() adds one or more CSS classes to an element. Syntax array.forEach(function(currentValue, index, arr), thisValue) element.classList.add('className') Example ...

Read More

JavaScript - Sort key value pair object based on value?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 4K+ Views

By using JavaScript's native array methods and functions, we can easily create custom sorting algorithms that will work for any type of object. In this article, we will discuss how to use these techniques in order to sort an object's key-value pairs by value. A key-value pair in JavaScript such as maps, dictionaries stores one value (the "key") associated with another value (the "value"). It can be used to store and access data quickly, as each element has its own unique identifier. For sorting key value pair object based on the value, we use sort() method in JavaScript. ...

Read More

Set object property in an array true/false, whether the id matches with any id from another array of objects in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 771 Views

In JavaScript, you often need to compare two arrays of objects and set a property (like matches) to true or false based on whether their IDs match. This is useful for data processing, filtering, and UI state management. An object in JavaScript is a collection of key-value pairs that represent properties and their values. Arrays are ordered lists that can store multiple values, including objects, and are accessed using numeric indices starting from 0. Syntax Basic array syntax: const arrayName = [item1, item2, ...]; Method 1: Using reduce() and map() The reduce() ...

Read More

Set PIN validation with JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 2K+ Views

In this article, we will discuss how to set up PIN validation using JavaScript. We will cover creating prompts for users to enter their PIN number, validating input against stored values, and returning appropriate responses based on the validation result. Data validation is the procedure used to ensure that user input is accurate, reliable, and clean. PIN validation typically checks the length, format, and data type to ensure the PIN contains only digits and meets specific requirements. We can validate PINs based on length (usually 4 or 6 digits) and ensure the input contains only numeric characters. Let's ...

Read More

Is it possible to change the value of the function parameter in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 4K+ Views

In this article we are going to find out whether it is possible to change the value of the function parameter in JavaScript. A function accepts certain values as parameters and later while calling this function we need to pass values for these parameters as arguments. Typically a function definition contains the name of the function, parameters (optional) and the body of the function. Syntax Following is the syntax for function parameters − function functionName(parameter1, parameter2, parameter3) { // Statements } Yes, it is possible to change the value of ...

Read More
Showing 111–120 of 307 articles
« Prev 1 10 11 12 13 14 31 Next »
Advertisements