Found 6710 Articles for Javascript

How to transform a JavaScript iterator into an array?

Mohit Panchasara
Updated on 16-Feb-2023 18:33:24

2K+ Views

In JavaScript, the iterator is a collection of elements through which we can iterate and access a single element every iteration. The set, map, or object is an iterator in JavaScript, and we can’t access the elements of the iterator using the index like the array. So, we first require to convert the iterator into the array. Here, we will use different methods like an array.from(), etc., to convert an iterator to the array. Use the for-of loop The for-of loop iterates through every element of the iterator lie set and map. Inside the for-of loop, we can ... Read More

How to skip over an element in .map()?

Mohit Panchasara
Updated on 16-Feb-2023 18:26:02

16K+ Views

In JavaScript, we sometimes require to skip array elements while using the map() method. For example, we need to map value from one array to another array after performing some mathematical operations on the element only if the array value is finite. In such cases, users can use the below approaches to skip over array elements while using the map() method. Use the if-else statement In the array.map() method, we can use the if-else statement to skip over the element. If the element fulfills the if-else statement condition, we need to return the element for mapping; Otherwise, we ... Read More

How to sort strings in JavaScript?

Shubham Vora
Updated on 14-Sep-2023 21:35:27

28K+ Views

The sorting string is to arrange strings in the dictionary or alphabetical order. It is usual to sort the array of strings while developing applications using JavaScript. In this tutorial, we will learn to sort strings in JavaScript. For example, string sorting is very useful here if you got some data from the API and want to show that data in the sorted order. Here, we will learn to sort strings using the built-in methods and various naïve approaches. Use the sort() method to sort strings In JavaScript, sort() is the built-in method we can use with the array. Generally, ... Read More

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

Shubham Vora
Updated on 16-Feb-2023 15:47:47

2K+ Views

To convert strings into lowercase and uppercase, we can use the JavaScript string class’s built-in methods like toLowerCase() and toUpperCase(). Furthermore, we can use the string length property or substring() method to split the string in half part. We will learn two approaches in this tutorial to convert half string to uppercase and the other half to lowercase using JavaScript. Use the for-loop, toUpperCase(), and toLowerCase() method We can use the for-loop to get the half-string. After that, we can use the toUpperCase() method to convert the first half of the string the uppercase. After that, we need to use ... Read More

How to check which tab is active using Material UI?

Shubham Vora
Updated on 16-Feb-2023 15:50:06

3K+ Views

Material-UI provides a variety of components that help us to 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 by ... Read More

Getting started with React Native? Read this first!

Shubham Vora
Updated on 16-Feb-2023 15:38:15

521 Views

React Native is a framework that allows developers to build mobile applications using JavaScript and React. It allows developers to use the same codebase for both iOS and Android platforms, making it a cost-effective and efficient solution for mobile development. React Facebook first introduced native in 2015 as an open-source project. It is based on React, a JavaScript library for building user interfaces, and allows developers to build mobile apps that look and feel like native apps. Use these tools and resources to build React Native app There are two main ways to install and set up a React Native ... Read More

How to use Checkbox inside Select Option using JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:33:06

8K+ 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 JQuery and JavaScript to manage the values of the checked checkboxes in the menu. Create a custom select menu The element of ... Read More

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

Shubham Vora
Updated on 16-Feb-2023 15:31:59

2K+ Views

In JavaScript, the async-await keyword is used to make the function asynchronous. If we make any function asynchronous, it works like multithreading and executes the code parallelly, which helps us to improve the application performance. Here, we will learn to use the await keyword outside the asynchronous function. Invoke the function immediately We will use the expression in this approach to invoke the function immediately. We can use the await keyword with the promises or any other function inside the function. Syntax Users can follow the syntax below to use the function expression to invoke the function immediately. (async () ... Read More

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

Shubham Vora
Updated on 16-Feb-2023 15:27:55

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() method 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 Users can follow the syntax below to use the ... Read More

How to swap two variables in JavaScript?

Shubham Vora
Updated on 16-Feb-2023 15:26:54

2K+ Views

We will learn to swap two variable values in JavaScript using various approaches. Let’s understand via example what swapping means. For example, we have two variables called variable1 and variable2. When we assign the values of variable2 to variable1 and the value of variable1 to variable2, we can say that we have swapped the values of variable1 and variable2. Use the temporary variable We can create a temporary variable, which means any variable to store the value of the first variable temporarily. After that, we can assign the value of the second variable to the first variable. Next, we can ... Read More

Advertisements