
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
AmitDiwan has Published 10744 Articles

AmitDiwan
785 Views
Let’s say the following is our array −var listOfNames = [ 'John', 'David', 'Bob' ];Following is our button −Click The Button To get the Reverse ValueNow, for array items in reverse, at first, reach the array length and decrement the length by 1. Then, print the contents ... Read More

AmitDiwan
4K+ Views
To assign multiple variables to the same value, the syntax is as followsvar anyVariableName1, anyVariableName2, anyVariableName3……….N; yourVariableName1=yourVariableName2=yourVariableName3=.........N=yourValue;Let’s say the following are our variables and we are assigning same value −var first, second, third, fourth, fifth; first=second=third=fourth=fifth=100;Examplevar first, second, third, fourth, fifth; first=second=third=fourth=fifth=100; console.log(first); console.log(second); console.log(third); console.log(fourth); console.log(fifth); console.log("The sum of ... Read More

AmitDiwan
151 Views
To convert a JavaScript object to key value, you need to use Object.entries() along with map(). Following is the code −Examplevar studentObject={ 101: "John", 102: "David", 103: "Bob" } var studentDetails = Object.assign({}, studentObject) studentDetails = Object.entries(studentObject).map(([studentId, studentName])=>({studentId ,studentName})); console.log(studentDetails);To run the above program, you need to ... Read More

AmitDiwan
374 Views
For this, use map() along with join(‘’).Then ‘’ is for new line. Following is the code −ExamplestudentDetails = [ [101, 'John', 'JavaScript'], [102, 'Bob', 'MySQL'] ]; var studentFormat = '||Id||Name||subjName||'; var seperate = ''; seperate = seperate + studentDetails.map(obj => `|${obj.join('|')}|`).join(''); studentFormat = studentFormat + seperate; console.log(studentFormat);To run ... Read More

AmitDiwan
275 Views
Let’s say the following is our current array −var listOfNames=["John", "Mike", "Sam", "Carol"];Use JSON.parse(JSON.stringify()) to create new array and set values from the old array above.Examplefunction createNewArray(listOfNames) { return JSON.parse(JSON.stringify(listOfNames)); } var listOfNames=["John", "Mike", "Sam", "Carol"]; var namesArray = listOfNames.slice(); console.log("The new Array="); console.log(namesArray);To run the above program, you ... Read More

AmitDiwan
355 Views
Let’s say, we are matching the current date and time with the business hours. We need to display whether the office is closed or open right now on the basis of current time.Get the hours from the current date and can use the ternary operator for close and open. Following ... Read More

AmitDiwan
611 Views
The recursive function calls itself with some base condition. Let’s say the following is our array with marks −var listOfMarks=[56, 78, 90, 94, 91, 82, 77];Following is the code to get the count of array elements −Examplefunction countNumberOfElementsUsingRecursive(listOfMarks) { if (listOfMarks.length == 0) { return 0; ... Read More

AmitDiwan
234 Views
Let’s say, first, we will set the start and end range and call the function:console.log(getRandomValueBetweenTwoValues(400, 480))We have passed start value 400 and end value 480. Let’s get the random value with Math.random() in JavaScript −Examplefunction getRandomValueBetweenTwoValues(startRange, endRange) { return Math.floor(Math.random() * (endRange - startRange + 1) + startRange); } ... Read More

AmitDiwan
4K+ Views
To check whitespace in a string, use the concept of indexOf(‘ ’). Following is the code −Examplefunction stringHasTheWhiteSpaceOrNot(value){ return value.indexOf(' ') >= 0; } var whiteSpace=stringHasTheWhiteSpaceOrNot("MyNameis John"); if(whiteSpace==true){ console.log("The string has whitespace"); } else { console.log("The string does not have whitespace"); ... Read More

AmitDiwan
1K+ Views
You can use match() with passing the variable name. The syntax is as follows −console.log(yourVariableName.match(yourMatchingVariableName));Examplevar senetence = 'My Name is John'; console.log("The actual value="); console.log(senetence); var matchWord = 'John'; console.log("The matching value="); console.log(matchWord); var matchRegularExpression = new RegExp(matchWord, 'g' ); console.log(senetence.match(matchWord));To run the above program, you need to use the ... Read More