Found 8895 Articles for Front End Technology

How to use a variable for a key in a JavaScript object literal?

Shubham Vora
Updated on 06-Apr-2023 15:00:13

9K+ Views

In JavaScript, sometimes, we are required to use the variables as an object key. For example, when fetching data from the API and not sure about all the response data attributes, we must iterate through the response object and store every property of it. However, we can’t use the variables as a key while creating the object, but after creating, we can add the variable properties to the object. Syntax Users can follow the syntax below to use a variable for a key in a JavaScript object. object[key] = value; In the above syntax, ‘key’ is a variable containing ... Read More

How to shard test files in protractor?

Shubham Vora
Updated on 05-Apr-2023 16:24:02

125 Views

Sharding is a method for distributing data or tasks across several machines to improve performance and scalability. Sharding is a technique used in test automation to distribute test cases among various instances of the testing framework and speed up test execution. Protractor is a testing framework that facilitates sharding test cases using the Jasmine test framework. To shard test files in Protractor, a configuration file must be written that details the path of the test files and the number of instances to be created. To shorten the overall test execution time, Protractor divides the test cases across several instances and ... Read More

How to update mouse location when scrolling with jQuery?

Shubham Vora
Updated on 05-Apr-2023 15:57:59

1K+ Views

In jQuery, we can trigger the ‘mousemove’ event to detect the mouse pointer's location on the web page. Also, we can detect the scroll using the ‘scroll’ event and subtract that value from the y position to get the relative mouse location. Using the ‘overflow-y: scroll’ CSS property, we can make any div scrollable. Syntax Users can follow the syntax below to get the relative mouse position while scrolling on the div. $('#main').scroll(function (event) { if (finalScroll != $('#main').scrollTop()) { location_y -= finalScroll; finalScroll = ... Read More

How to throw an error when using a property of an object?

Shubham Vora
Updated on 05-Apr-2023 15:55:41

451 Views

In JavaScript, an object contains the properties in the key-value format. We can access any property of an object using the property name by taking the object as a reference. Sometimes, we try to access the object property that doesn’t exist in the object. In such cases, we get the undefined value. Let’s understand it by the example below. Example (Accessing the Object Properties) In the example below, we have created the object and added some properties. Also, we have added some nested properties. After that, we try to access the ‘prop5’ property which is a nested property of the ... Read More

How to throw an error in an async generator function in JavaScript ?

Shubham Vora
Updated on 05-Apr-2023 15:53:00

1K+ Views

The code often throws an error, and handling errors is more important. JavaScript also allows users to throw a custom error using the ‘throw’ keyword. We can catch the errors in the catch block. We can use the try-catch syntax to catch errors thrown by normal functions. Let’s understand it by the example below. Example 1 (Throw Errors in Regular Function) In the example below, we have created the throwError() regular function, which uses the throw keyword to throw an error with the custom error message. We have executed the function inside the try block. If the function throws any ... Read More

How to take HTML form data as text and send them to html2pdf?

Shubham Vora
Updated on 23-Nov-2023 13:08:46

1K+ Views

The html2pdf is a JavaScript package that allows developers to convert the html to canvas, pdf, image, etc. It takes html as a parameter and adds that to the pdf or required document. Furthermore, it also allows users to download the document after adding the html content to that. Here, we will access the form and add it to the pdf using the html2pdf npm package. We will see different examples of adding form data to pdf. Syntax Users can follow the syntax below to take html form data as text and send them to html2pdf. var element = document.getElementById('form'); ... Read More

How to switch the language of the page using JavaScript?

Shubham Vora
Updated on 05-Apr-2023 15:50:29

7K+ Views

Whenever you develop a website or application for a worldwide business, you must also focus on which language your audience can understand. For example, English is an international language, but in some parts of the world, people don’t understand English as they speak German, Spanish etc. However, if you have observed, then some websites provide the option to change the website's language. You just need to click on the button, which changes the whole website's language. Have you ever thought about how it is possible? Here, we will learn to switch the language of the web page using JavaScript. Syntax ... Read More

How to Style Google Custom Search Manually using CSS?

Shubham Vora
Updated on 05-Apr-2023 15:47:14

580 Views

Have you ever tried to build a custom search engine? If yes, you are aware of how much effort it takes. The first thing is that we need to create a search algorithm that should show the best matching results when any user searches. It can take a lot of time. Rather than wasting time on creating our search engine, what if we use the Google custom search engine? Yes, you heard right! Google allows us to integrate the search engine on our website, and Google handles everything when any user searches for something on our website. Integrating the Google ... Read More

How to store JavaScript functions in a queue and execute in that order?

Shubham Vora
Updated on 05-Apr-2023 15:45:32

521 Views

Sometimes, developers may require to store the function in the queue and execute it in the order it is stored in the queue. In JavaScript, we can create a queue using the array. We can use the push() method of the array to enqueue the function in the queue and the shift() method to deque the function from the queue. Below, we will see examples of storing JavaScript functions in the queue and executing them in the queue order. Syntax Users can follow the syntax below to store JavaScript functions in a queue and execute in that order. while (queue.length ... Read More

How to store data to DOM?

Shubham Vora
Updated on 05-Apr-2023 15:42:53

1K+ Views

Storing data in the DOM means storing data in plain text format. For example, we store data in the state variable while using React or any other reactive framework. When the user updates the data in the input field, it stores updated data in the state variable. So, we store data in the state variable before we submit the form. At the time of submitting the form, we use the values of the state variables. In vanilla JavaScript, we can do the same, like storing data in plain text format, and whenever we require to submit the form, we can ... Read More

Advertisements