JavaScript Location Protocol Property

AmitDiwan
Updated on 11-May-2020 13:29:26

205 Views

The JavaScript location protocol property returns the protocol used by the current URL.Following is the code for Location protocol Property in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample{       font-size: 18px;       font-weight: 500;       color: red;    } Location protocol Property CLICK HERE Click on the above button to get the location protocol    let sampleEle = document.querySelector(".sample");    document.querySelector(".Btn").addEventListener("click", () => {       sampleEle.innerHTML = 'The protocol used by the website = ' + location.protocol;    }); OutputOn clicking the “CLICK HERE” button −

JavaScript let

AmitDiwan
Updated on 11-May-2020 13:25:57

203 Views

The JavaScript Let keyword introduced in 2015 allows us to define block scoped variables.Following is the code for declaring variable using Let keyword in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample{       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript Let CLICK HERE Click on the above button to access the varible    let sampleEle = document.querySelector(".sample");    document.querySelector(".Btn").addEventListener("click", () => {     ... Read More

Length of Array Objects in JavaScript

AmitDiwan
Updated on 11-May-2020 13:06:39

353 Views

The length property in JavaScript returns the size of the object. Following is the code for the length of string and array objects −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,    .result {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript length property CLICK HERE Click on the above button to find the length of the array    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result");    let arr = [1, 2, "A", "B", "D"];    sampleEle.innerHTML = arr;    document.querySelector(".Btn").addEventListener("click", () => {       resultEle.innerHTML += "The array length is = " + arr.length;    }); OutputOn clicking the ‘CLICK HERE’ button −

JavaScript lastIndex Property

AmitDiwan
Updated on 11-May-2020 13:03:01

123 Views

The lastIndex property in JavaScript returns the index position when a match occurs and the next match then resumes from that position only. The lastIndex property works only if the ‘g’ modifier is set.Following is the code for the lastIndex property in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample,    .result {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript lastIndex Property The king bought an expensive ring. ... Read More

Get Value of GET Parameters from URL in JavaScript

AmitDiwan
Updated on 11-May-2020 12:57:08

238 Views

To know the value of GET parameters from URL in JavaScript, the code is as follows −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } GET parameters from URL https://www.google.com?imageSize=440&color=blue CLICK HERE Click on the above button to get the imageSize and color value from the above URL    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result");   ... Read More

JavaScript JSON.parse() Method

AmitDiwan
Updated on 11-May-2020 12:44:40

405 Views

The JSON parse() method is used for parsing a JSON string and then creating a JavaScript object from it.Following is the code for JSON parse() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JSON parse() Method {"name":"Rohan", "sports":["Cricket", "Football"], "country":"India"} CLICK HERE Click on the above button to parse the above JSON string    let ... Read More

JavaScript JSON and HTML

AmitDiwan
Updated on 11-May-2020 12:42:33

262 Views

To generate HTML using JSON data, the code is as follows −Note − JSONPlaceholder is a fake Online REST API for Testing and PrototypingExample Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JSON arrays EMPLOYEE NAME CLICK HERE Click on the above button to fill the employee table    let sampleEle = document.querySelector(".employee");    document.querySelector(".Btn").addEventListener("click", () => {       fetch("https://jsonplaceholder.typicode.com/users")       .then((response) => response.json())       .then((result) => {          result.forEach((element) => {             sampleEle.innerHTML += "" + element.name;          });       });    }); OutputOn clicking the ‘CLICK HERE’ button −

JavaScript JSON Arrays

AmitDiwan
Updated on 11-May-2020 12:39:37

304 Views

Arrays in JSON are similar to Arrays in JavaScript. JavaScript JSON arrays looks like this −let obj = {    name:'Rohan',    sports : ['cricket','Football','volleyball','hockey'] }Following is the code for JSON arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JSON arrays CLICK HERE Click on the above button to access JSON array    let sampleEle = document.querySelector(".sample");    let obj = {       name:'Rohan',  sports : ['cricket','Football','volleyball','hockey']    }    document.querySelector(".Btn").addEventListener("click", () => {       obj.sports.forEach(item=>{          sampleEle.innerHTML += item + '';       })    }); OutputOn clicking the ‘CLICK HERE’ button −

JavaScript Infinity Property

AmitDiwan
Updated on 11-May-2020 12:34:59

142 Views

The JavaScript infinity property displays infinity if the upper limit of the floating-point number is exceed and − infinity if the lower limit of the floating point number has has been exceeded.Following is the code for JavaScript infinity property −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 ... Read More

JavaScript Immediately Invoked Function Expressions (IIFE)

AmitDiwan
Updated on 11-May-2020 12:32:28

157 Views

The JavaScript Immediately Invoked Function Expressions (IIFE) is a JavaScript function that executes immediately after it has been defined so there is no need to manually invoke IIFE.Following is the code for Immediately Invoked Function Expressions (IIFE) in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JavaScript Immediately Invoked Function Expressions (IIFE)    let sampleEle = document.querySelector(".sample");    (function () {       sampleEle.innerHTML ="This code is invoked immediately as soon as it is defined";    })(); Output

Advertisements