Javascript Articles

Page 12 of 534

How can I delete all cookies with JavaScript?

Vrundesha Joshi
Vrundesha Joshi
Updated on 11-Mar-2026 1K+ Views

To delete all cookies with JavaScript, you can try to run the following code. Here, we’re using an array and the split() method to get all the cookies and finally delete themExample                    var num = 1;          function addCookie(){             document.cookie = num+" = "+num;             num++;          }          function listCookies(){             var result = document.cookie;             document.getElementById("list").innerHTML = result;          }          function removeCookies() {             var res = document.cookie;             var multiple = res.split(";");             for(var i = 0; i < multiple.length; i++) {                var key = multiple[i].split("=");                document.cookie = key[0]+" =; expires = Thu, 01 Jan 1970 00:00:00 UTC";             }          }                     ADD       LIST COOKIES       REMOVE       Cookies List          

Read More

How to detect all active JavaScript event handlers?

Nishtha Thakur
Nishtha Thakur
Updated on 11-Mar-2026 823 Views

The simplest solution is to use jQuery to detect all active JavaScript event handlers.ExampleYou can try to run the following code to detect active event handlers                          var myEvent = $("#demo");          myEvent.mouseover(function() {});          $.each(myEvent.data("events"), function(i, e) {             alert(i);          });                     Demo Text    

Read More

How to change font size in HTML?

Syed Javed
Syed Javed
Updated on 11-Mar-2026 134K+ Views

To change the font size in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property font-size. HTML5 do not support the tag, so the CSS style is used to add font size.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to change the font size in an HTML page,         ...

Read More

How to set text font family in HTML?

Samual Sam
Samual Sam
Updated on 11-Mar-2026 28K+ Views

To change the text font family in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML tag, with the CSS property font-family. HTML5 do not support the tag, so the CSS style is used to add font size.Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML tag or external style sheet.ExampleYou can try to run the following code to change the text font family in an HTML page   ...

Read More

How to create a chart from JSON data using Fetch API in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 5K+ Views

In this article, we are going to explore on how to create a chart after fetching the JSON data. To fetch JSON data we use fetch() method of Fetch API. We will first fetch the data and once the data is available we will feed it into the system to create a chart. The Fetch API provides a simple interface for accessing and manipulating HTTP requests and responses.Syntaxconst response = fetch(resource [, init])Parametersresource − This is the resource path from where the data is fetched.init − It defines any extra options such as headers, body, etc.ApproachThe steps can be defined ...

Read More

Mathematics summation function in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

ProblemWe are required to write a JavaScript function that takes in a number n. Our function should return the sum of all the natural numbers from 1 to n including both 1 and nExampleFollowing is the code −const num = 34; const summation = (num = 1) => {    let res = 0;    for(let i = 1; i

Read More

Returning the nth even number using JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 635 Views

ProblemWe are required to write a JavaScript function that takes in a number n. And our function should simply return the nth even number in natural numbers.ExampleFollowing is the code −const num = 67765; const nthEven = (num = 1) => {    const next = num * 2;    const res = next - 2;    return res; }; console.log(nthEven(num));Output135528

Read More

process.env() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 11-Mar-2026 537 Views

The process.argv() method is used for getting the user environment object. This object will contain all the information about the environment on which this command is being executed.Syntaxprocess.env()ParametersSince it returns an object for the user environment. It does not need any inputs from the user as such.ExampleCreate a file with name – env.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node env.jsenv.js// Node.js program to demonstrate the use of process.env // Importing the process module const process = require('process'); // Printing the ...

Read More

Array thirds with equal sums in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 166 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers as the first and the only argument. Our function should return true if and only if we can partition the array into three non-empty parts with equal sums, false otherwise.For example, if the input to the function is −const arr = [3, 3, 6, 5, -2, 2, 5, 1, -9, 4];Then the output should be −const output = true;Output ExplanationBecause, 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4ExampleThe code for this will be −const ...

Read More

Maximum consecutive 1s after n swaps in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 219 Views

ProblemWe are required to write a JavaScript function that takes in a binary arr (array that contains only 0 or 1), arr, as the first argument, and a number, num, as the second argument.We can change at most num 0s present in the array to 1s, and our function should return the length of the longest (contiguous) subarray that contains only 1s after making these changes.For example, if the input to the function is −const arr = [1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0]; const num = 2;Then the output should be −const output = 6;Output ...

Read More
Showing 111–120 of 5,339 articles
« Prev 1 10 11 12 13 14 534 Next »
Advertisements