Articles on Trending Technologies

Technical articles with clear explanations and examples

Passing unknown number of arguments to a function in Javascript

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 3K+ Views

JavaScript allows functions to accept any number of arguments, even if the function definition specifies a different number of parameters. This flexibility is useful when creating functions that need to handle variable amounts of data. When defining a function, the variables listed in parentheses are called parameters. When calling the function, the actual values passed are called arguments. JavaScript provides two main approaches to handle unknown numbers of arguments. Basic Example: Fixed Parameters Functions with fixed parameters will only use the specified number of arguments, ignoring any extras: Passing ...

Read More

JavaScript program to access browsing history

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 877 Views

In this article, we will learn to access browsing history using JavaScript. In web development, accessing a user's browsing history can improve user experience and provide personalized content. However, due to privacy concerns and security reasons, modern web browsers limit the amount of browsing history accessible via JavaScript. What is Browsing History? Browsing history refers to the list of web pages that a user has visited over a while. Browsers typically store this data locally, allowing users to navigate back and forth through the pages they've visited. The window.history Object In JavaScript, the window.history object allows ...

Read More

Sort array based on presence of fields in objects JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 319 Views

In JavaScript, you can sort arrays of objects based on the presence of specific fields using a custom comparator function. This technique is useful when you need to prioritize objects with complete information. Problem Statement Let's say we have an array of people objects where some have both firstName and lastName, some have only one of these properties, and others have neither: const people = [{ firstName: 'Ram', id: 301 }, { firstName: 'Shyam', lastName: 'Singh', ...

Read More

Group values in array by two properties JavaScript

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

We have an array of objects like this: const arr = [ { value: 12, gap: 1 }, { value: 13, gap: 1 }, { value: 14, gap: 1 }, { value: 15, gap: 1 }, { value: 19, gap: 2 }, { value: 21, gap: 1 }, { value: 22, gap: 1 }, { value: 23, gap: 1 }, { value: ...

Read More

Program to test the equality of two arrays - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 191 Views

We are required to write a JavaScript function that takes in two arrays of literals and checks the corresponding elements of the array and it should return true if all the corresponding elements of the array are equal otherwise it should return false. Let's write the code for this function − Example Following is the code − const arr1 = [1, 4, 5, 3, 5, 6]; const arr2 = [1, 4, 5, 2, 5, 6]; const areEqual = (first, second) => { if(first.length !== second.length){ ...

Read More

How can I delete all cookies with JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 15-Mar-2026 1K+ Views

To delete all cookies with JavaScript, you need to iterate through existing cookies and set their expiration date to the past. JavaScript doesn't provide a direct method to clear all cookies at once, so we must delete them individually. How Cookie Deletion Works Cookies are deleted by setting their expires attribute to a past date. When the browser sees an expired cookie, it automatically removes it from storage. Method 1: Basic Cookie Deletion This approach splits the cookie string and deletes each cookie by name: function deleteAllCookies() { var cookies ...

Read More

Set the background color of an element with CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 448 Views

To set the background color of an element, use the background-color property in CSS. This property accepts color values in various formats including color names, hex codes, RGB, and HSL values. Syntax background-color: color-value; Example Here's how to set background colors using different methods: Background Color Example This text has a blue background color. ...

Read More

How to compare two string arrays, case insensitive and independent about ordering JavaScript, ES6

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 856 Views

We need to write a function that compares two strings to check if they contain the same characters, ignoring case and order. This is useful for validating anagrams or checking string equivalence. For example: const first = 'Aavsg'; const second = 'VSAAg'; isEqual(first, second); // true Using Array Sort Method This method converts strings to arrays, sorts the characters, and compares the results. We extend the String prototype to add a sort method. const first = 'Aavsg'; const second = 'VSAAg'; const stringSort = function(){ return this.split("").sort().join(""); ...

Read More

Check whether a value exists in JSON object?

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

In JavaScript, you can check whether a value exists in a JSON object (or array of objects) using several approaches. Let's explore different methods to find values efficiently. Consider the following JSON object structure: var apiJSONObject = [ {subjectName: "MySQL"}, {subjectName: "Java"}, {subjectName: "JavaScript"}, {subjectName: "MongoDB"} ] Using for Loop (Traditional Approach) The basic approach uses a for loop to iterate through the array and check each object: var apiJSONObject = [ {subjectName: "MySQL"}, ...

Read More

Find the average of all elements of array except the largest and smallest - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 394 Views

We are required to write a JavaScript function that takes in an array of numbers and returns the average of its elements excluding the smallest and largest numbers. Approach The solution involves finding the minimum and maximum values, calculating the total sum, then computing the average of remaining elements after excluding min and max values. Example const arr = [1, 4, 5, 3, 5, 6, 12, 5, 65, 3, 2, 65, 9]; const findExcludedAverage = arr => { const creds = arr.reduce((acc, val) => { ...

Read More
Showing 18611–18620 of 61,297 articles
Advertisements