Javascript Articles

Page 231 of 534

How to use array that include and check an object against a property of an object?

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

The task is to check whether the array contains a particular value. Also, we need to check if the array contains the particular object with the given property. This tutorial will use the array.includes() and array.some() methods to check whether the array contains the value or object with a particular property. Use the array.includes() method to check values exist in the array The array.includes() method allows us to check whether the array contains any value. In simple terms, we can search for values in the array using the array.includes() method. Syntax array.includes(value, startIndex); ...

Read More

How to add an element to a JSON object using JavaScript?

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

In this article, you will understand how to add an element to a JSON object using JavaScript. JSON objects are key-value pairs separated by colons and surrounded by curly braces {}. JavaScript provides two main ways to add new properties: bracket notation and dot notation. Using Bracket Notation Bracket notation is useful when property names contain special characters or are stored in variables. var jsonObject = { members: { host: "hostName", viewers: ...

Read More

How to calculate minutes between two dates in JavaScript?

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

In this article, you will understand how to calculate minutes between two dates in JavaScript. The Date object works with dates and times. Date objects are created with new Date(). To calculate minutes between dates, we convert the time difference from milliseconds to minutes using mathematical operations. Method 1: Using a Function In this example, we create a reusable function to find the time difference in minutes. function minutesDiff(dateTimeValue2, dateTimeValue1) { var differenceValue = (dateTimeValue2.getTime() - dateTimeValue1.getTime()) / 1000; differenceValue /= 60; return Math.abs(Math.round(differenceValue)); } ...

Read More

How to use await outside of an async function in JavaScript?

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

In JavaScript, the await keyword can only be used inside async functions. However, there are several techniques to work with asynchronous code when you need to use await at the top level or outside of async functions. Here, we will learn different approaches to handle asynchronous operations outside of regular async functions. Using Immediately Invoked Function Expression (IIFE) The most common approach is to wrap your code in an immediately invoked async function expression. This allows you to use await within the function scope. Syntax (async () => { let ...

Read More

How to use Checkbox inside Select Option using JavaScript?

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

Sometimes, we require to use the checkbox inside the select option. We can allow users to select multiple options by introducing the checkboxes with the select option. However, if we use the multiple attributes with the tag, it allows us to select them by pressing the 'ctrl + left click', but it is a bad UX. So, we can introduce the checkbox inside the menu to improve the user experience. Here, we will use JavaScript to manage the values of the checked checkboxes in the custom menu. Create a Custom Select Menu The ...

Read More

How to create half of the string in uppercase and the other half in lowercase?

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

To convert half of a string to uppercase and the other half to lowercase, we can use JavaScript's built-in string methods like toUpperCase(), toLowerCase(), and substr() (or substring()). This tutorial demonstrates two effective approaches to achieve this transformation. Using for-loop with toUpperCase() and toLowerCase() This approach uses loops to iterate through the string and convert each character individually based on its position. Syntax for (let i = 0; i < length / 2; i++) { newStr += string[i].toUpperCase(); } for (i = length / 2; i < length; i++) { ...

Read More

How to check which tab is active using Material UI?

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

Material-UI provides a variety of components that help us build user interfaces with a consistent look and feel. One of the components that Material-UI provides is the Tabs component, which allows us to create tabbed interfaces in our applications. In this tutorial, we will learn how to check which tab is active using Material-UI, a popular React UI library. Use the useState Hook to Check Which Tab is Active Users can follow the steps below to check which tab is active using Material UI. Step 1 − First, users need to install Material-UI. We can do this ...

Read More

How a Polygon is different from a Polyline in FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 532 Views

We can create a Polyline object by creating an instance of fabric.Polyline while fabric.Polygon can be used to create a Polygon instance. A polyline object can be characterised by a set of connected straight-line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. A polygon always connects the first point to the last to make a closed area while a polyline doesn't. This can be proved by the examples given below. Syntax new fabric.Polyline(points: Array, options: Object) new fabric.Polygon(points: Array, options: ...

Read More

How to stop browser's back button using JavaScript?

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

Stopping the browser's back button means preventing users from navigating to the previous page. Sometimes, we need to prevent users from going back from the current page for security purposes. For example, most banking sites don't allow you to go back when you are doing transactions through online banking. If users go back mid-transaction, it can create issues. So, they only allow you to either complete the transaction or cancel it and start again. Here, we will learn various approaches to prevent users from going back to the previous web page using JavaScript. Using window.history.forward() Method ...

Read More

How to store a key => value array in JavaScript?

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

In JavaScript, storing data in key-value pairs is essential for organizing information like user details, configuration settings, or any structured data. JavaScript provides several approaches to achieve this functionality. We can use different data structures, such as objects or maps in JavaScript, to store data in the key-value format. Using Objects to Store Key-Value Pairs In JavaScript, objects are the most common way to store data in key-value format. Objects allow dynamic property assignment and easy data retrieval using keys. Syntax let object = {}; object[key] = value; // or object.key = value; ...

Read More
Showing 2301–2310 of 5,340 articles
« Prev 1 229 230 231 232 233 534 Next »
Advertisements