 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Web Development Articles - Page 437 of 1049
 
 
			
			3K+ Views
Let’s say the following is our comma separated text in div − This, is, the, first, JavaScript, program To convert comma separated text into separate lines, you need to use trim() along with split() on the basis of comma(, ).Example Live Demo Document This, is, the, first, JavaScript, program var allTheData = document.querySelector('.commaSeparated').textContent.trim().split(', ') var separateList = '' allTheData.forEach(function(value) { separateList += '' + value + ''; }); separateList += ''; document.querySelector(".commaSeparated").innerHTML = separateList; To run the ... Read More
 
 
			
			5K+ Views
Let’s say the following is our nested objects −var details = [ { id:"101", firstName:"John", lastName:"Smith", age:25, countryName:"US", subjectDetails: { subjectId:"Java-101", subjectName:"Introduction to Java" }, }, { "uniqueId": "details_10001" } ]Use map() along with typeOf to access nested objects. Following is the code −Examplevar details = [ { id:"101", firstName:"John", lastName:"Smith", ... Read More
 
 
			
			843 Views
Let’s say the following is our object −var details = { firstName: 'John', lastName: '', countryName: 'US' }Use Object.keys() along with find() to get the key name with empty value. Following is the code −Examplevar details = { firstName: 'John', lastName: '', countryName: 'US' } var result = Object.keys(details).find(key=> (details[key] === '' || details[key] === null)); console.log("The key is="+result);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo118.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo118.js The key is=lastNameRead More
 
 
			
			5K+ Views
Let’s say the following is our object −var apiJSONObject = [ {subjectName:"MySQL"}, {subjectName:"Java"}, {subjectName:"JavaScript"}, {subjectName:"MongoDB"} ]Let’s check for existence of a value “JavaScript” −Examplevar apiJSONObject = [ {subjectName:"MySQL"}, {subjectName:"Java"}, {subjectName:"JavaScript"}, {subjectName:"MongoDB"} ] for(var i=0;i node demo117.js The search found in JSON Object
 
 
			
			3K+ Views
Let’s see an example wherein we are validating input text onsubmit −Example Live Demo Document function validateTheForm(){ var validation = (document.getElementById('txtInput').value == 'gmail'); if(!validation){ alert('Something went wrong...Plese write gmail intext box and click'); return false; } return true; } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” ... Read More
 
 
			
			2K+ Views
For this, use forEach() loop along with push(). Following is the code −Examplevar studentDetails= [ { studentId:1, studentName:"John" }, { studentId:1, studentName:"David" }, { studentId:2, studentName:"Bob" }, { studentId:2, studentName:"Carol" } ] studentObject={}; studentDetails.forEach (function (obj){ studentObject[obj.studentId] = studentObject[obj.studentId] || []; studentObject[obj.studentId].push(obj.studentName); }); console.log(studentObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo116.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo116.js { '1': [ 'John', 'David' ], '2': [ 'Bob', 'Carol' ] }
 
 
			
			1K+ Views
You can create an associative array in JavaScript using an array of objects with key and value pair.Associative arrays are basically objects in JavaScript where indexes are replaced by user defined keys.Examplevar customerDetails= [ { "customerId":"customer-1", "customerName":"David", "customerCountryName":"US" }, { "customerId":"customer-2", "customerName":"Bob", "customerCountryName":"UK" }, { "customerId":"customer-3", "customerName":"Carol", "customerCountryName":"AUS" } ] for(var i=0;i node demo115.js David Bob Carol
 
 
			
			792 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 of the particular index in reverse order.Example Live Demo Document Click The Button To get the Reverse Value var listOfNames = [ 'John', 'David', 'Bob' ]; count=listOfNames.length-1; function reverseTheArray(){ document.getElementById('reverseTheArray').innerHTML = listOfNames[count]; count--; if (count
 
 
			
			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 all values="+(first+second+third+fourth+fifth));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo114.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo114.js 100 100 100 100 100 The sum of all values=500Read More
 
 
			
			158 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 use the following command −node fileName.js.Here, my file name is demo113.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo113.js [ { studentId: '101', studentName: 'John' }, { studentId: '102', studentName: 'David' }, { studentId: '103', studentName: 'Bob' } ]