Found 8591 Articles for Front End Technology

Converting a string to a date in JavaScript

Aman Kumar
Updated on 19-Dec-2022 12:11:06

4K+ Views

In this article, we are going to discuss how to convert a string value to a Date object in JavaScript. There are two ways to achieve this − Using the constructor of the Date class − This constructor accepts a string value representing the date value, converts it into a Date object, and returns the result. Using the Date.parse() method − Same as the Date constructor this method accepts a string value parses and returns the date value in the form of milliseconds. Let us see these solutions with examples − Using the Date() constructor The most commonly used way ... Read More

Inserting string at position x of another string using Javascript

Aman Kumar
Updated on 19-Dec-2022 12:07:26

929 Views

In this article, you are going to learn how to insert a string at a position in another string. JavaScript does not give a direct way to achieve this. For this, we can use the slice method. The slice method extracts a section of a string and returns a new string. In addition to the slice() method we can also use the methods join() and substr(). Using the slice() Method of the String class This slice() method gets parts of the string and returns the extracted part from the string and makes a new string. Following is the syntax ... Read More

How to Clear the JavaScript Console in Google Chrome

Aman Kumar
Updated on 19-Dec-2022 12:05:07

16K+ Views

In this article we are going to learn how to clear the JavaScript Console in Google Chrome. We have various methods to clear the console; but our question is why do we need to clear the console? Sometimes we have lots of commands and logs printed in any browser console which makes it look substandard and packed with output. So, we need to clear the console. And there are multiple ways to clear the console of google chrome. Using the console.clear() method This method will clear the console and display the message on the console that the console was clear. ... Read More

Dynamically creating keys in JavaScript associative array

Aman Kumar
Updated on 19-Dec-2022 12:01:59

4K+ Views

In this article, we are going to discuss how to create keys in a JavaScript associative array dynamically. Associative arrays are dynamic objects that are user defined as needed. When you assign values to keys in a variable of types array, then the array is transformed into an object, and it loses the attributes and methods or array. i.e. the length attributes have no effect because the variables are no longer of the type array. JavaScript associative arrays are same as any other literals. You can add keys to these using the square brackets notation you can add keys to ... Read More

Why Ember.js is the best javascript frame work?

Aman Kumar
Updated on 19-Dec-2022 11:58:06

242 Views

Ember.js is the best framework. The user of Ember.js is increasing day by day. The popularity of ember.js is 6.3% of JavaScript developers currently using ember. Its popularity has stood over the last two years. Ranked 4th most popular JavaScript framework. Ember.js is an MVVM (Model−view−view−model) model framework for complex and multiple-page applications and it is an open-source framework. It is a very redefined control system that helps you to integrate with the new version without any problems. Ember.js is a free javascript client-side framework it is used for developing web applications. It is providing the complete solution which contains ... Read More

How to set a countdown timer in javascript?

Aman Kumar
Updated on 19-Dec-2022 11:36:37

9K+ Views

We can set a countdown timer in JavaScript using the setInterval() method. This method continuously calls a function or executes a code snippet with a fixed time delay between every call. The setInterval() method calls a function at described intervals in milliseconds. It continues calling the function until the clearInterval() is called, or the window is closed. SyntaxFollowing is the syntax of this method − setInterval(function, milliseconds); The setInterval method accepts two parameter functions and milliseconds. function − A function containing a block of code designed to perform a particular task. milliseconds − it is the time interval ... Read More

How to break the _.each function in underscore.js

Ayush Gupta
Updated on 02-Dec-2019 06:45:59

331 Views

You can't break from each method. It copies the native forEach method's behavior and the native forEach doesn't provide to escape the loop (other than throwing an exception).You can use other functions like −_.find: it breaks out of the loop when the element is found. For example,_.find([1, 2, 3, 4], (element) => {    // Check your condition here    if (element === 2) {       return true;    }    // Do what you want with the elements here    // ... });Throw an exception from each. For example,try {    _([1, 2, 3, 4]).each((element) => {       // Check your condition here       if (element === 2) {          throw new Error();       }       // Do what you want with the elements here       // ...    }) } catch (e) {    // Do nothing. }

How to do image preloading with javascript?

Aman Kumar
Updated on 19-Dec-2022 11:41:43

1K+ Views

The preload attribute specifies how the author thinks about the media file should be loaded when the page loads. The preload attributes allow the author to provide hints to the browser about how much time should take to load a page, it will lead to the best user experience. Preload also tells the browser about critical resources that you want to load as soon as possible. This is especially useful for resources that are not easily appreciable, such as fonts included in stylesheets, background images, or resources loaded from a script. Using preload helps here because the images start loading ... Read More

How to get the size of a json object in JavaScript?

Aman Kumar
Updated on 19-Dec-2022 11:33:57

10K+ Views

In this article, we will learn about various methods to get the size of a JSON object in JavaScript. Getting the size of the object in JavaScript is same as the counting the total number of keys of an object. In general, we can get the size or number of keys of a JSON object in JavaScript by using two methods. Using object.keys() The object.keys() method returns an array of the given object of its countable properties name with the same order as we get as a normal loop. Following is the syntax of this method − Object.keys(name_of_object).length; ... Read More

How do I add a class to a given element using Javascript?

Aman Kumar
Updated on 19-Dec-2022 11:31:44

936 Views

In JavaScript, there are various approaches to add a class to an element. We can use the .className attribute or the .add() method to add a class name to the specific element. The class attribute can be used in CSS to perform some tasks for the elements with the parallel class name. Using the className Property We can use this property to add a class to an HTML element without restoring its existing class. This property can be used to execute the value of the class attribute of an element. If a class is already declared for an element, ... Read More

Advertisements