Found 8591 Articles for Front End Technology

How to change the color of a button when the input field is filled – JavaScript?

AmitDiwan
Updated on 09-Nov-2020 08:34:56

2K+ Views

Let’s say the following is our button −Press MeOn filling the below input field, the color of the above button should change −ExampleFollowing is the code − Live Demo            Document           UserName:                Press Me    function changeTheColorOfButtonDemo() {       if (document.getElementById("changeColorDemo").value !== "") {          document.getElementById("buttonDemo").style.background = "green";       } else {          document.getElementById("buttonDemo").style.background = "skyblue";       }    } To run ... Read More

How to create a password generator - JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:42:33

778 Views

These days, password generators can be found all over the internet. Without a strong enough password, websites frequently won't let you establish an account. The task we are going to perform was how to create a password generator JavaScript. Let’s dive into the article for getting better understanding on creating a password generator. For this, use Math.random() to create random passwords. Using Math.random() method A floating-point pseudo-random number in the range [0, 1], 0 (inclusive), and 1(exclusive) is returned by the JavaScript function Math.random(). You can then resize this random number to fit the necessary range. Syntax Following is the ... Read More

Do JavaScript arrays have an equivalent of Python’s "if a in list"?

Yaswanth Varma
Updated on 21-Apr-2023 16:44:43

688 Views

In JavaScript Arrays are used to store multiple values in a single variable. This is compared to a variable that can store only one value. Each item in an array has a number attached to it, called a numeric index, that allows you to access it. In JavaScript, arrays start at index zero and can be manipulated with various methods. This basically tells about true or false. If the item is found then it returns true, else false is returned. You can achieve the same in JavaScript arrays, using includes. Let’s dive into the article to understand more about the ... Read More

Get current date/time in seconds - JavaScript?

Yaswanth Varma
Updated on 27-Jan-2025 12:34:26

13K+ Views

In JavaScript, there are built-in methods for getting the current date and time in seconds. We are going to perform this in two ways − Using the Date.now() method Using a new date getTime() method Let’s dive into the article for getting better understanding on getting current date time in seconds. Using Date.now() method The Date.now() static method returns the milliseconds that ... Read More

In JavaScript, what is meant by 'a function expression is always a constant value'?

AmitDiwan
Updated on 09-Nov-2020 08:27:33

132 Views

If the const is used in a program, and if you try to reassign the value to const variable then an error will arise.Let’s say the following is our const variable −const result = (first, second) => first * second;Now, we will try to reassign a value to the const variable and an erro can be seen in the output.ExampleFollowing is the code −const result = (first, second) => first * second; result = first => first =first*10; console.log(result(10, 20)); To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo284.js.OutputThis will produce ... Read More

How to remove all blank objects from an Object in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 16:46:59

3K+ Views

The task at hand is to learn how to remove all blank objects from a JavaScript object. Let’s consider the following object − const details = { name: 'John', age: {}, marks: { marks: {} } } We need to remove the black objects above You can use forEach() along with typeof and delete to remove blank objects. Let’s dive into the article for getting better understanding on removing blank objects. Using reduce() A reducer function is run for each element of an array using the reduce() method. The function's ... Read More

How to count number of occurrences of repeated names in an array - JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 17:05:26

1K+ Views

An array in JavaScript is a group of identically typed elements that are stored in adjacent memory locations and may each be separately referred to using an index to a special identifier. Let’s consider an array consisting of occurrences of repeated names. The array looks like this − var details = [ { studentName: "John", studentAge: 23 }, { studentName: "David", studentAge: 24 }, ... Read More

Hide a video tag on a web page - JavaScript

AmitDiwan
Updated on 09-Nov-2020 08:18:01

4K+ Views

Let’s say we have the following sample video tag on a web page        You cannot play video here...... To hide a video on a web page, use yourVariableName.style.display=’none’.ExampleFollowing is the code −            Document    .hideVideo {       display: block;       z-index: 999;       margin-top: 10px;       margin-left: 10px;    }               You cannot play video here......        var hideVideo = document.getElementsByClassName("hideVideo")[0];    hideVideo.style.display = ... Read More

Make strings in array become keys in object in a new array in JavaScript?

Yaswanth Varma
Updated on 21-Apr-2023 17:23:05

2K+ Views

The task we are going to perform in this article is make strings in array become keys in object in a new array in JavaScript. Let’s consider a simple array − let array= ['bike', 'car'] Now, we are going to use map() to convert the above array to a new array (keys in an object). The array will then look like this − let newArray= [{shorts: []}, {tees: []}, ] Let’s dive into the article to learn more about on making a strings in array become keys in object in a new array in JavaScript. Using map() The ... Read More

Implement Bubble sort with negative and positive numbers – JavaScript?

AmitDiwan
Updated on 09-Nov-2020 08:13:49

908 Views

Let’s say the following is our unsorted array with negative and positive numbers −var arr = [10, -22, 54, 3, 4, 45, 6];ExampleFollowing is the code to implement Bubble Sort −function bubbleSort(numberArray, size) {    for (var lastIndex = size - 1; lastIndex > 0; lastIndex--) {       for (var i = 0; i < lastIndex; i++) {          if (numberArray[i] > numberArray[i + 1]) {             var temp = numberArray[i];             numberArray[i] = numberArray[i + 1];             numberArray[i + ... Read More

Advertisements