Found 9053 Articles for Front End Technology

How to perform numeric sort in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:39:30

11K+ Views

In this tutorial, we will learn how to perform the numeric Sort in JavaScript. We can arrange the given numerical values by numerical sorting into ascending or descending order In JavaScript, we use the sort () method to sort numerical values. This method sorts the arrays of numbers, strings, and objects. It sorts the elements of an array and changes the order of the original array's elements. The array elements are cast to strings to determine the order and then compared and sorted. arr.sort() Where arr is the array of numeric elements that need to be sorted, this method ... Read More

How to get the value of the rel attribute of a link in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 09:15:29

2K+ Views

In this tutorial, we will learn how to get the value of the rel attribute of a link in JavaScript. The rel attribute expressed the relationship between the current document or website and the linked document or website. The search engine uses this attribute to get more information about the link, so it is important for the SEO of the website. The rel attribute can have different values like alternate, author, external, nofollow, etc.; each value means different information about the link. For example, ‘alternate’ means the link represents an alternate version of the current document. Using document.getElementById() Method In ... Read More

Are both addition and concatenation same in JavaScript?

Sravani Alamanda
Updated on 08-Dec-2022 08:43:53

1K+ Views

We can't say whether both are the same or both are different. In some cases, addition and concatenation will have the same result, but in some cases, they will be different. It is completely based on the type of variables. We will see it in detail below We use the + operator for addition and the concat() method for concatenation in JavaScript. In some cases, both the + operator and the concat() method returns the same result. Adding and concatenating two strings using the + operator and the concat() method returns the same result. We can also apply the ... Read More

Is it a good practice to end switch with defaults in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 11:54:20

577 Views

In this tutorial, we will learn if it is a good practice to end switch with defaults in JavaScript. In JavaScript, we generally use the if or if-else statements if we need to check any conditions. Still, if we need to check multiple conditions for an expression, it becomes very complex and unorganized, so we use the switch statements for that situation. The switch statement compares the value of an expression to a series of case clauses, then executes statements after the first case clause that matches the value, and so on, until a break statement is met. If no ... Read More

What are the best practices to be followed while using JavaScript?

Shubham Vora
Updated on 15-Nov-2022 10:50:56

86 Views

In this tutorial, we will learn the best practices to follow while using JavaScript. JavaScript is used in almost every website to make it more user interactive. Throughout the years, ECMAScript has released different versions of JavaScript. Each version has enhanced functionalities and new features, so it is important to know the best practices to follow while using JavaScript. The following are the best practices to be followed while using JavaScript − Meaningful Variable and Function Name The variables’ and functions’ names should be meaningful to their uses. In JavaScript, we use the variable to store some data, and the ... Read More

How to get the value of the hreflang attribute of a link in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 09:09:29

597 Views

In this tutorial, we will learn how to get the value of the hreflang attribute of a link in JavaScript. The hreflang is an attribute of a link or anchor tag which specifies the language of the linked document or href attribute. It is used by search engines to understand the link’s language and the targeted geographical location of the website. For better SEO hreflang attribute must be used. A single language or combination of language and region is used as the value of the hreflang attribute. It uses the language code ISO-639-1 and region code ISO-3166-1. For example: If ... Read More

How to remove options from a dropdown list with JavaScript?

Prabhdeep Singh
Updated on 07-Nov-2022 06:01:56

10K+ Views

This tutorial teaches us how to remove the options from a dropdown list using JavaScript. Usually, this is not frequent that users get the option to remove any option from the dropdown list but this is possible if the option is provided by the programmer. If the programmer wants to provide the option to remove the dropdown then in JavaScript it is possible with the help of the remove() method. Using the DOM user can select the option to remove and by providing a function it could be passed to the remove method which will remove it. Let’s look into ... Read More

How to show the index of the selected option in a dropdown list with JavaScript?

Abhishek Kumar
Updated on 21-Sep-2022 07:48:25

10K+ Views

We use the selectedIndex property in JavaScript to show the index of the selected option in a dropdown list. We use the id of the dropdown list to access the element using JavaScript and then call selectedIndex on it to get the index of the selected option in the dropdown list. Dropdown lists are an important part of user interface utility. It is a list of options from which one or multiple options can be selected by the user. These responses to these dropdown lists are then collected and the required course of action is taken by the user. A ... Read More

How to get the number of options in the dropdown list with JavaScript?

Shubham Vora
Updated on 26-Aug-2022 13:25:34

8K+ Views

This tutorial will show different ways to get the number of options in the drop-down list with JavaScript. While filling out any form online, users have to add unique information using the input method. However, the options they get in the drop-down list are already determined. Since there can be limited options mentioned in the drop-down, you might have to check the number using JavaScript. Using options.length method to get the number of drop-down options One of the simple ways to get access to the list of options is to get the list by its Id. We will use a ... Read More

How to select multiple options in a dropdown list with JavaScript?

Prabhdeep Singh
Updated on 07-Nov-2022 08:14:24

10K+ Views

In this tutorial, we are going to learn how to select multiple options in a dropdown list with JavaScript. Basically, we are going to make two buttons, one is a drop-down button in which we provide more than one option, and another is a normal button connected to the multiFunc() function with an id of the dropdown button, when we click this button then we are able to select multiple options in the drop-down button. In this tutorial we are using two properties of JavaScript one is DOM property i.e. document.getElementById and another one is multiple properties use to choose ... Read More

Advertisements