
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
674 Views
To find all subsets of a set, use reduce() along with map() in JavaScript. Let’s say, we are passing the set [8, 9] and finding the subsets.Exampleconst findAllSubsetsoOfGivenSet = originalArrayValue => originalArrayValue.reduce( (givenSet, setValue) => givenSet.concat( givenSet.map(givenSet => [setValue, ...givenSet]) ), [[]] ); console.log(findAllSubsetsoOfGivenSet([8, 9]));To ... Read More

AmitDiwan
405 Views
To convert an object into an array, use push() in JavaScript. Following is the code −ExamplestudentDetails= [ { studentName:"Chris", studentMarks:34}, { studentName:"David", studentMarks:89} ] var convertIntoArray = []; for (var i = 0; i < studentDetails.length; i++) { convertIntoArray.push(studentDetails[i].studentName); } console.log(convertIntoArray);To run ... Read More

AmitDiwan
698 Views
To cut a string after X characters, use substr() function from JavaScript. Following is the JavaScript code wherein we are cutting the string after 9th character −Examplevar myName="JohnSmithMITUS"; console.log("The String="+myName) var afterXCharacter = myName.substr(0, 9) + "\u0026"; console.log("After cutting the characters the string="+afterXCharacter);Above, the unicode “\u0026” will replace all the ... Read More

AmitDiwan
143 Views
For this, you can use find() along with a map(). Let’s say we have student records with name, rollno and subject.Examplevar firstObject= [ { "FirstName": "David", "RollNo": "105", "Subject": "MongoDB" }, { "FirstName": "Mike", "RollNo": "110", "Subject": "JavaScript"} ]; var secondObject= [ { "FirstName": "Bob", "RollNo": "101", ... Read More

AmitDiwan
320 Views
To separate the special character, use the concept of match() with Regular Expression. The syntax is as follows −yourStringName.flatMap(anyVariableName => yourVariableName.match(/\w+|\W+/g));Let’s say, the following is our array with special characters in between values −var allNames = ['John-Smith', 'David', 'Carol%Taylor'];Let’s now see how to separate text with special characters. Following is ... Read More

AmitDiwan
737 Views
To extract the value of the , use −document.getElementById(“yourTextIdValue”).textContentExample Live Demo Document This is the JavaScript.... var originalText = document.getElementById("myText").textContent; console.log(originalText); To run the above program, just save the file name anyName.html(index.html) and right ... Read More

AmitDiwan
711 Views
Let’s say we have the following strings. One of them is beginning with a question mark i.e. punctuation −var sentence1 = 'My Name is John Smith.' var sentence2 = '? My Name is John Smith.'We need to check whether any of the above two sentences begin with punctuation. To check ... Read More

AmitDiwan
186 Views
Let’s say the following is our string with whitespace −var fullName=" John Smith ";Use replace() and set Regex in it to remove whitespaces.Examplefunction removeSpacesAtTheBeginningAndTheEnd(name) { return name.toString().replace(/^\s+|\s+$/g, ''); } var fullName=" John Smith "; var valueAfterRemovingSpace=removeSpacesAtTheBeginningAndTheEnd(fullName) console.log(valueAfterRemovingSpace);To run the above program, you need to use the following command −node ... Read More

AmitDiwan
454 Views
Let’s say the following is our array −var numbers = [10, 3, 40, 50, 20, 30, 100]We need to search two numbers from the above array elements, whose sum is 80.For this, use simple for loop with if condition.Examplefunction specificPairsOfSumOfTwoNumbers(numbers, totalValue) { var storeTwoNumbersObject = {} ... Read More

AmitDiwan
4K+ Views
Let’s say the following is our JSON array −var details = [ { "customerDetails": [ { "customerName": "John Smith", "customerCountryName": "US" ... Read More