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 10740 Articles
AmitDiwan
161 Views
Use the concept of freeze() from JavaScript to disallow adding new properties to an object, altering of object properties, etc.Following is the code wherein we are changing the value but the previous value still remains since we cannot alter properties using freeze() −Exampleconst canNotChangeTheFieldValueAfterFreeze = {value1 : 10, value2: 20 ... Read More
AmitDiwan
3K+ Views
Let us first create a nested object −var details = { "teacherDetails": { "teacherName": ["John", "David"] }, "subjectDetails": { "subjectName": ["MongoDB", "Java"] } }Let us now extract the keys. Following is the code −Examplevar details = { ... Read More
AmitDiwan
500 Views
To set sleep i.e. delay, use the concept of setTimeout(). It takes values in milliseconds i.e.1000 milliseconds = 1 second 2000 milliseconds = 2 seconds, etc.For our example, we will add two values with a delay of 5 seconds i.e. 5000 milliseconds. Following is the code −Examplevar firstValue=10; var secondValue=20; ... Read More
AmitDiwan
185 Views
To get largest numbers passed using reduce(), use the Math.max() function. Following is the code −const getBiggestNumberFromArraysPassed = allArrays => allArrays.reduce( (maxValue, maxCurrent) => maxValue.push(Math.max(...maxCurrent)), maxValue), []); console.log(getBiggestNumberFromArraysPassed([[45, 78, 3, 1], [50, 34, 90, 89], [32, 10, 90, 99]]));To run the above program, you need to use the following command ... Read More
AmitDiwan
391 Views
Let’s say the following are our two strings −var originalName = "JOHNDOE"; var removalName = "JOHN"We need to remove the second string from first. For this, use replace() along with reduce().Exampleconst removeCharactersFromAString= (removalName, originalName)=>removalName.split('').reduce((obj, v)=>obj.replace(v, ''), originalName); var originalName = "JOHNDOE"; var removalName = "JOHN" console.log(removeCharactersFromAString(removalName, originalName));To run the above ... Read More
AmitDiwan
315 Views
To un-nest array of objects, use the concept of map(). Let’s say the following are our array of objects −const studentDetails = [ { "studentId": 101, "studentName": "John", "subjectDetails": { "subjectName": "JavaScript" } ... Read More
AmitDiwan
474 Views
To fetch the highest value, use the Math.max() from JavaScript. Since, we want the one with maximum value, use the Object.values.Exampleconst studentMarksDetails= { marks1:78, marks2:69, marks3:79, marks4:74 } const maximumMarks = Math.max(...Object.values(studentMarksDetails)); console.log("The highest marks="+maximumMarks); for (const key of Object.keys(studentMarksDetails)){ if (studentMarksDetails[key] == maximumMarks) { ... Read More
AmitDiwan
799 Views
To remove extra spaces, you need to use trim() along with regular expressions. Following is our string with spaces before applying trim() −var sentence="My name is John Smith ";Now, we will remove the extra spaces as in the below code −Examplevar sentence="My name is John Smith "; console.log("The actual value="); ... Read More
AmitDiwan
590 Views
In order to modify the key values, you need to use regular expressions along with Object.fromEntries().Examplevar underscoreSpecifyFormat = str => str.replace(/(_)(.)/g, (_, __, v) => v.toUpperCase()), JsonObject = { first_Name_Field: 'John', last_Name_Field: 'Smith'}, output = Object.fromEntries(Object.entries(JsonObject).map(([key, value]) => [underscoreSpecifyFormat(key), value])); console.log("The JSON Object="); console.log(output);To run the above program, you need ... Read More
AmitDiwan
279 Views
To remove ‘0’. ‘undefined’ and empty values, you need to use the concept of splice(). Let’s say the following is our array −var allValues = [10, false, 100, 150 ,'', undefined, 450, null]Following is the complete code using for loop and splice() −Examplevar allValues = [10, false, 100, 150 ,'', ... Read More