AmitDiwan has Published 10744 Articles

How to group JSON data in JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 14:11:54

3K+ Views

To group JSON data, you need to extract all the keys and use the push(). Following is the code −Examplevar details= {    "1":    {       name:"John"    },    "2":    {       name:"John"    },    "3":    {       name:"David" ... Read More

Call a JavaScript class object with variable?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 14:09:58

1K+ Views

Let’s say the following is our variable −var message = 'This is the Class Demo';Following is our object, var object = new FirstClass(message)The class FirstClass −class FirstClass{    constructor( message){       this.message = message;    } }We will use eval() to call a JavaScript class object with variable. ... Read More

How to get a subset of JavaScript object's properties?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:55:30

169 Views

Let’s say the following is our object −var details ={    firstName: "John",    lastName: "Smith",    age:21,    subjectName:"JavaScript",    marks:89,    coutryName:"US",    collegeName:"MIT",    passoutYear:2018 };Following is the code to fetch only a subset −Examplevar details ={    firstName: "John",    lastName: "Smith",    age:21,    subjectName:"JavaScript", ... Read More

How to convert comma separated text in div into separate lines with JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:52:21

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 ... Read More

How to use JavaScript map() method to access nested objects?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:36:30

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 ... Read More

How to get key name when the value contains empty in an object with JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:32:44

836 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' ... Read More

Check whether a value exists in JSON object?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:28:22

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 ObjectRead More

HTML form action and onsubmit validations with JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:23:41

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 ... Read More

Creating an associative array in JavaScript with push()?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:20:18

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"   ... Read More

Creating an associative array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2020 13:17:38

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"    }, ... Read More

Advertisements