Web Development Articles - Page 508 of 1049

Explain common code blocks in JavaScript switch statement?

AmitDiwan
Updated on 15-Jul-2020 13:56:19

261 Views

Following is the code to implement common code blocks in JavaScript switch statement −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript Switch statement Enter day 1-7 CHECK Click on the above button to check which day it is    let dayVal = document.querySelector(".day");    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       switch (parseInt(dayVal.value)) {     ... Read More

How to verify if a JavaScript object is an array? Explain with examples.

AmitDiwan
Updated on 15-Jul-2020 13:53:49

149 Views

The JavaScript Array.isArray() method is used to verify if a JavaScript object is an array or not based on the Boolean value returned by it.Following is the code to verify if JavaScript object is an array −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Verify if a JavaScript object is array CLICK HERE Click on the above button to verify if the above ... Read More

How to set the day of a date in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:49:34

152 Views

Following is the code to set the day of a date in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Setting day of the date in JavaScript CLICK HERE Click on the above button to change the day of the above date object    let sampleEle = document.querySelector('.sample');    let resEle = document.querySelector(".result");    let dateObj = new Date();   ... Read More

What are associative Arrays in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:45:07

4K+ Views

Associative arrays are basically objects in JavaScript where indexes are replaced by user defined keys. They do not have a length property like normal array and cannot be traversed using normal for loop.Following is the code for associative arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Associative array in JavaScript CLICK HERE Click on the above button to create a associative array ... Read More

Creating a JavaScript array with new keyword.

AmitDiwan
Updated on 15-Jul-2020 13:43:05

198 Views

Following is the code for creating a JavaScript array with new keyword −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Creating array with new keyword CLICK HERE Click on the above button to create a new array and display it    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {    let arr = new Array(1, 2, 3, 4, "A", "B", "C", "D");       resEle.innerHTML = "arr = " + arr;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button−

What is meant by Splicing an array in JavaScript? Explain with an example

AmitDiwan
Updated on 15-Jul-2020 13:34:04

536 Views

Splicing an array means to use the Array.splice() method for adding or removing items from the array. The items removed are returned as an array.Following is the code for splicing an array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Splicing an array in JavaScript CLICK HERE Click on the above button to add items after second element   ... Read More

How to print positive and negative infinity values in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:28:01

216 Views

Following is the code for printing positive and negative infinity values in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .num {       font-size: 18px;       font-weight: 500;    } JavaScript Infinity property 1.797693134862315E+10308 -1.797693134862315E+10308 CLICK HERE Click on the above button to add and subtract the above floating numbers by 1 respectively    let sampleEle = document.querySelector(".sample");    let num1 = document.querySelectorAll(".num")[0];    let num2 = document.querySelectorAll(".num")[1];    document.querySelector(".Btn").addEventListener("click", () => {       num1.innerHTML = +num1.innerHTML + 1;       num2.innerHTML = +num2.innerHTML - 1;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

How to search for a string in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:25:44

266 Views

Following is the code for searching a string in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Searching a string in JavaScript The spring season is about to come. CLICK HERE Click on the above button to find the string 'spring' in the above string    let btnEle = document.querySelector(".btn");    let sampleEle = document.querySelector(".sample").innerHTML;    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "The string spring is found at position " + sampleEle.search("spring");    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

NaN and Infinity example in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:23:32

213 Views

Following is the code to implement NaN and Infinity in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } NaN and Infinity in JavaScript CLICK HERE Click on the above button to see nan and infinity example    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "9/0 = " + 9 / 0 + "";       resEle.innerHTML += 'Number("AJKL") = ' + Number("AJKL") + "";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

How to delete object properties in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:21:27

190 Views

Following is the code for deleting object properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Delete object properties in JavaScript Before Deleting After deleting CLICK HERE Click on the above button to delete object properties    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let obj = {       firstName: ... Read More

Advertisements