Set Scroll View with Intervals in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:17:40

718 Views

For this, use the concept of scrollTop and scrollHeight.Example Live Demo Document    #scrollDemo {       height: 300px;       overflow-y: scroll;    }    #scrollDataFeatures {       height: 500px;       background-color: skyblue;    } See the below Message and Scroll UP    var scrollData = document.getElementById("scrollDemo");    scrollData.scrollTop = scrollData.scrollHeight    setInterval(() =>{       var heading3Data = document.createElement("h3");       heading3Data.innerHTML = "Scroll Down...Please Scroll UP"       scrollData.appendChild(heading3Data);       scrollData.scrollTop ... Read More

Child Node Count in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:14:54

677 Views

Use children.length to get the count of child node.Example Live Demo Document List Of Subject Names are as follows: Javascript MySQL MongoDB Java Python    var arrayValueOfSubject =    document.getElementById('subjectName').parentNode;    console.log("The count of child node    is="+arrayValueOfSubject.children.length); To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VSCode Editor.OutputThis will produce the following output −

Display All Values of an Array in P Tag using JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:11:57

764 Views

For this, you can use .data(anyArrayObject). Following is the code −Example Live Demo Document    const arrayValues = [1000000001,"John","Smith",100, 200, 3000]    var originalData = d3.select("body").selectAll("p")    .data(arrayValues)    .enter()    .append("p")    .text(function(allValuesOfArray){       console.log(allValuesOfArray+" ");       return allValuesOfArray;    }) To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.OutputThis will produce the following output −

Match Strings That Aren't Entirely Digits in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:09:49

80 Views

Let’s say the following is our complicated string −var values = 'studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678"';You can use regular expression to match strings. Following is the code −Examplevar regularExpression = /(? node demo187.js Original Value=studentId:"100001",studentName:"John Smith",isTopper:true,uniqueId:10001J-10001,marks:78,newId:"4678" The string that are not entirely digits= [ '10001J-10001' ]

Changing Value of Nested Object Keys in JavaScript

AmitDiwan
Updated on 14-Sep-2020 08:08:17

624 Views

For this, use dot(.) notation along with square brackets ([]).Examplevar details = {    "customer": {       "customerDetails": {          "otherDetails": [             {                "customerDetails": {                   "isMarried": false                },             },             {                "customerDetails": {                   "isMarried": false         ... Read More

Unselect Multiple Checkboxes on Button Click in jQuery

AmitDiwan
Updated on 14-Sep-2020 08:05:37

469 Views

For this, use jQuery() with id property. Following is the code −Example Live Demo Document    .changeColor {       color: red    }; Javascript MySQL MongoDB Python    jQuery("#selectDemo").click(function () {       jQuery(this).toggleClass("changeColor");       if (jQuery(this).hasClass("changeColor")) {          jQuery(".isSelected").prop("checked", true);             jQuery(this).val("Want To UnSelect All Values");       } else ... Read More

Use Object Like an Array with Map Function in JavaScript

AmitDiwan
Updated on 14-Sep-2020 07:48:51

143 Views

For this, use Object.keys() as well as Object.values() and map() for the result.Exampleconst object = {    name: 'John',    age: 21,    countryName: 'US',    subjectName: 'JavaScript' } const allKeysOfObject = Object.keys(object); console.log("The all keys are=" + allKeysOfObject); const allValues = Object.values(object); console.log("The all values are=" + allValues); console.log("The use of map is as follows="); allKeysOfObject.map(k => { console.log(object[k]) })To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo185.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo185.js The all keys are=name, age, countryName, subjectName The all values are=John, 21, ... Read More

Get the First Element of Array in JavaScript

AmitDiwan
Updated on 14-Sep-2020 06:42:43

997 Views

You can use simple for loop along with some if else condition to get the array’s first element in JavaScript.The logic is that, first of all check the array length is greater than 1 or not if the length is not equal to 1 that means there is no element in the array. So, go to the else condition and set the value undefined and print any message at the console. If there is an element in an array, set the first index value to any variable and terminate the loop with the help of break and print the message ... Read More

Concatenate Two Arrays of Objects and Remove Duplicates in JavaScript

AmitDiwan
Updated on 14-Sep-2020 06:39:13

245 Views

For this, use map() along with find(). Following is the code −Examplevar details1 = [    {       productDetails:       {          isSold: true,          productId:101       }    },    {       productDetails:       {          isSold: true,          productId:103       }    } ] var details2 = [    {       productDetails:       {          isSold: false,          productId:101       }    } ] var details3 = details1.map(details1Object=>{    var newObject= details2.find(obj=>obj.productDetails.productId    === details1Object.productDetails.productId)    return newObject? newObject : details1Object }) console.log(details3)To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo183.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo183.js [    { productDetails: { isSold: false, productId: 101 } },    { productDetails: { isSold: true, productId: 103 } } ]

Declare and Define Multiple Variables in One Statement with JavaScript

AmitDiwan
Updated on 14-Sep-2020 06:36:57

293 Views

To declare and define multiple variables in one statement, you can use below syntax −var anyVariableName1=yourValue1, anyVariableName2=yourValue2, anyVariableName3=yourValue3, anyVariableName4=yourValue4, . . NExamplevar firstName="My First Name is David", lastName="My Last Name is Miller", place="I live in AUS"; console.log(firstName); console.log(lastName); console.log(place);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo182.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo182.js My First Name is David My Last Name is Miller I live in AUSRead More

Advertisements