Javascript Articles

Page 66 of 534

Continuing a loop in functional programming JavaScript.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 162 Views

Following is the code for continuing a loop in functional programming JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Continuing a loop in functional programming JavaScript Click here Click on the above button to iterate fruitArr and skip mango and peach or not    let resEle = document.querySelector(".result");    let fruitArr = ["apple", "mango", "peach", "papaya", "watermelon"];    document.querySelector(".Btn").addEventListener("click", () => {       fruitArr.some(function (fruit) {          if (fruit === "mango" || fruit === "peach") {             return false;          }          resEle.innerHTML += fruit + "";       });    }); OutputOn clicking the ‘Click here’ button −

Read More

Creating ‘Copy to Clipboard’ feature on a web page with JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 237 Views

Following is the code for creating ‘copy to clipboard’ feature on a web page with JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    input,    button {       padding: 8px;    } Creating Copy to Clipboard Copy Text Click on the above button to copy text from the textbox    let resEle = document.querySelector(".result");    let ...

Read More

The generator.throw() method in JavaScript.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 205 Views

The generator.throw() method is used to pass an error to the yield. The generator resumes the execution after throw has been called by throwing an error and returning object with properties done and value.Following is the code for generator.throw() in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } generator.throw() method in ...

Read More

How to reduce arrays in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 183 Views

Following is the code to reduce arrays in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: blueviolet;    }    button {       padding: 8px;    } Reduce arrays javascript [1,3,5,6,9,22,15] Sum Click on the above button to sum the elements of the array    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let sampleEle = document.querySelector(".sample");    let arr = [1, 3, 5, 6, 9, 22, 15];    sampleEle.innerHTML = arr;    BtnEle.addEventListener("click", () => {       resEle.innerHTML =       "Sum = " +       arr.reduce((sum, prev) => {          return sum + prev;       });    }); OutputOn clicking the ‘Sum’ button −

Read More

How to check if a document is ready in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 776 Views

Following is the code to check if a document is ready in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Check if a document is ready Check Click on the above button to see document state    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    resEle.innerHTML = document.readyState + "";    BtnEle.addEventListener("click", () => {       if (document.readyState === "complete") {          resEle.innerHTML = "The page has finished loading completely";       } else {          resEle.innerHTML = "The page is still loading";       }    }); OutputOn clicking the ‘Check’ button −

Read More

Can we re-throw errors in JavaScript? Explain.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 247 Views

Exception can be rethrown after they have been caught by using the throw after catching the exception.Following is the code to re-throw errors in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Re-throw errors in JavaScript CHECK Enter a number bigger than 40 to re throw error;    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result"); ...

Read More

TextDecoder and TextEncoder in Javascript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 650 Views

TextEncoder is used to convert a given string to utf-8 standard. It retunes an Uint8Array from the string.TextDecoder is used to covert a stream of bytes into a stream of code points. It can decode UTF-8 , ISO-8859-2, KOI8-R, GBK etc.Following is the code for TextDecoder and TextEncoder in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: ...

Read More

Calculating average of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 586 Views

Following is the code for calculating average of an array in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: blueviolet;    }    .sample {       color: red;    } Calculating average of an array Check Click on the above button to see document state    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let sampleEle = document.querySelector(".sample");    let arr = [1, 2, 3, 4, 5, 11, 22];    sampleEle.innerHTML = arr;    BtnEle.addEventListener("click", () => {       let sum = 0;       arr.forEach((item) => (sum += item));       resEle.innerHTML = "The average of the array = " + sum / arr.length;    }); OutputOn clicking the ‘Calculate’ button −

Read More

How to convert an Image to blob using JavaScript?

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

Following is the code to convert an image to blob using JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Convert an Image to blob using JavaScript Convert Click on the above button to convert the above image to blob    let BtnEle = document.querySelector(".Btn");    let resEle = gdocument.querySelector(".result");    BtnEle.addEventListener("click", () => {       ...

Read More

How to access JavaScript properties?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 320 Views

There are three ways to access JavaScript properties −Using dot property access: object.propertyUsing square brackets notation: object[‘property’]Using object destructuring: let {property} = objectFollowing is the code for accessing JavaScript object properties −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: blueviolet;    }    .sample {       color: red;    } Access JavaScript object properties {a:22, b:44} Access Click on the above ...

Read More
Showing 651–660 of 5,338 articles
« Prev 1 64 65 66 67 68 534 Next »
Advertisements