Found 8591 Articles for Front End Technology

Remove property for all objects in array in JavaScript?

Yaswanth Varma
Updated on 19-Jul-2023 15:12:53

2K+ Views

The task we are going to perform in this articles is to “Remove property for all objects in array in JavaScript”. A collection of key-value pairs constitutes an object in JavaScript. A key-value pair among them is referred to as an object property. Any data type, including Number, String, Array, Object, etc., can be used for both the keys and values of properties There are two methods: one is mutable and uses the delete operator; the other is immutable and uses object restructuring. Let’s discuss this method. The delete operator The delete operator eliminates both the property's value and the ... Read More

Array.prototype.fill() with object passes reference and not new instance in JavaScript?

AmitDiwan
Updated on 26-Oct-2020 11:08:01

178 Views

To fix this, you can use map() in JavaScript.The syntax is as follows −var anyVariableName= new Array(yourSize).fill().map(Object);ExampleFollowing is the code −var arrayOfObject = new Array(5).fill().map(Object); console.log(arrayOfObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo311.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo311.js [ {}, {}, {}, {}, {} ]

How to make a setInterval() stop after some time or after a number of actions in JavaScript?

AmitDiwan
Updated on 26-Oct-2020 11:06:41

2K+ Views

Use some conditions to stop after some time.The below code will stop in half a minute.ExampleFollowing is the code −            Document    var now = new Date().getTime();    var interval = setInterval(function () {       if (new Date().getTime() - now > 30000) {          clearInterval(interval);          return;       }       console.log("working");    }, 2000); To run the above program, save the file name anyName.html(index.html) and right click on the file. Select the option “Open with live server” in VS Code editor.OutputThis will produce the following output −

How to sort an array of integers correctly in JavaScript?

AmitDiwan
Updated on 26-Oct-2020 11:04:21

380 Views

To sort an array of integers, use sort() in JavaScript.ExampleFollowing is the code −var arrayOfIntegers = [67, 45, 98, 52]; arrayOfIntegers.sort(function (first, second) {    return first - second; }); console.log(arrayOfIntegers);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo310.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo310.js [ 45, 52, 67, 98 ]

How to stop the loop for JavaScript scroll down?

Yaswanth Varma
Updated on 18-Jan-2023 11:17:48

778 Views

JavaScript scroll down loops can be extremely annoying and disruptive to a web page. Fortunately, it is relatively easy to stop the loop if you know what steps to take. In this article, we will discuss how to stop the JavaScript scroll down loop so that your website visitors don't have to keep scrolling endlessly. We'll also provide some tips on preventing these types of issues in the future. JavaScript method ScrollBy() scrolls the web page to the specific number of pixels. The clearInterval()in JavaScript The clearInterval() is a JavaScript function that is used to stop the execution of a ... Read More

JavaScript subtraction of two float values?

Yaswanth Varma
Updated on 18-Jan-2023 11:44:20

3K+ Views

As we are familiar with the subtraction of two float values and we know how to use the subtraction condition between float values. To correctly subtract two float values, use parseFloat() along with toFixed(). Let’s dive into the article to learn more about JavaScript subtraction of two float values. The parseFloat()function The string is taken as input and converted into a floating-point value using the parseFloat() method. The function returns NaN, or not a number, if the string is empty or if its first character is not a numeric value. Up until the point where it runs into ... Read More

Use jQuery to get values of selected checkboxes?

AmitDiwan
Updated on 26-Oct-2020 10:56:01

437 Views

Yes, we can use jQuery to get values of selected checkboxes using the concept of input. We have to also use the :checked selector.ExampleFollowing is the code −            Document        Cricket        Listening Music Reading NewsPaper Click Me    $(document).ready(function () {       $("button").click(function () {          $('input[name="checkDemo"]:checked').each(function () {             console.log(this.value);          });       });    }); To run the above program, save the ... Read More

Replace whitespace in different elements with the same class in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:04:10

449 Views

In this article we are going to learn about replace whitespace in different elements with same class in JavaScript. Let’s look into the article to learn more about replacing whitespaces in different elements. Using split() and join() Methods The split() method divides a string into several substrings and returns them as an array. When a separator is present in the string, the string is split according to the separator that was specified as a parameter. This parameter specifies the space character (" ") to divide the string whenever a space is present. A separator is used to join an array ... Read More

How can I show a hidden div when a select option is selected in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:06:21

17K+ Views

Showing and hiding elements is a common task in JavaScript. It can be used to create dynamic user interfaces, where the content changes depending on the user's input or interaction with the page. One way of doing this is to show a hidden div when a select option is selected. This article will guide you through how to do this using JavaScript. A Boolean attribute is the one that was chosen. It indicates that a choice should be preselected when the page loads if it is present. In the drop-down list, the pre-selected option will be shown first. To ... Read More

Why addEventListener to 'select' element does not work in JavaScript?

Yaswanth Varma
Updated on 18-Jan-2023 12:02:43

9K+ Views

When a user changes the value of an element, the , , and elements fire the change event. The change event does not always fire for every change to an element's value, unlike the input event. Instead, use querySelector() along with addEventListener(). Let’s discuss one by one to understand how they will work. The addEventListener() Method − The addEventListener() is a method used to register an event handler for the specified event type on the current element. It allows you to specify a function that will be called whenever the specified event occurs on the element. Following ... Read More

Advertisements