AmitDiwan has Published 10740 Articles

Concatenate two arrays of objects and remove repeated data from an attribute in JavaScript?

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 06:39:13

272 Views

For this, use map() along with find(). Following is the code −Examplevar details1 = [    {       productDetails:       {          isSold: true,          productId:101       }    },    {       productDetails:     ... Read More

How can I declare and define multiple variables in one statement with JavaScript?

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 06:36:57

318 Views

To declare and define multiple variables in one statement, you can use below syntax −var anyVariableName1=yourValue1, anyVariableName2=yourValue2, anyVariableName3=yourValue3, anyVariableName4=yourValue4, . . NExamplevar firstName="My First Name is David", lastName="My Last Name is Miller", place="I live in AUS"; console.log(firstName); console.log(lastName); console.log(place);To run the above program, you need to use the following command ... Read More

How do I check whether a checkbox is checked in jQuery?

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 06:34:44

348 Views

To check whether a checkbox is checked in jQuery, use the concept of toggle(). Following is the code −Example Live Demo Document Your name is Adam Smith    $('#selectName').click(function() {       $("#txtName").toggle(this.checked);    }); To ... Read More

Display in console if Select list value contains a value from an array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 14-Sep-2020 06:30:59

691 Views

Let’s say the following is our dropdown −    John    David    Chris    Mike    Bob    Carol Following is our array −var listOfNames = ["Chris", "Robert", "Mike"];To check whether the selected list value contains a value in array, use −$(‘select’).on(‘change’).Example Live Demo Document ... Read More

From a list of IDs with empty and non-empty values, retrieve specific ID records in JavaScript

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 09:01:44

252 Views

Let’s say the following is our list −var details=[    {id:101, name:"John", age:21},    {id:111, name:"David", age:24},    {id:1, name:"Mike", age:22},    {id:"", name:"Sam", age:20},    {id: 1, name:"Carol", age:23},    {id:null, name:"Robert", age:25},    {id:1, name:"Adam", age:24},    {id:"", name:"Chris", age:23} ];You can use the concept of filter to ... Read More

Convert a list of string coords into two float lists of Lat/Longitude coordinates in JavaScript?

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 09:00:14

610 Views

Let’s say the following are our coordinates −var listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"];To convert the above into two float lists of Latitude and Longitude, use split() on the basis of comma(, ) along with map().Examplevar listOfStrings = ["10.45322, -6.8766363", "78.93664664, -9.74646646", "7888.7664664, -10.64664632"]; var latitude = []; ... Read More

Fetch values by ignoring a specific one in JavaScript?

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 08:57:41

394 Views

To ignore a specific value, use the logical Not (!) operator in if condition and fetch watching you want to include.Examplevar customerDetails=[    {       customerName:"John",       customerAge:28,       customerCountryName:"US"    },    {       customerName:"David",       customerAge:25,     ... Read More

Select random values from an array in JavaScript?

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 08:56:31

559 Views

To select random values from an array, use the concept of Math.random().Examplevar subjectNames = ["Javascript", "MySQL", "Java", "MongoDB", "Python", "Spring Framework"]; for(var index = subjectNames.length - 1; index > 0; index--){    var rndIndex = Math.floor(Math.random() * (index + 1));    var subjNameTemp = subjectNames[rndIndex];    subjectNames[rndIndex] = subjectNames[index];   ... Read More

Get only specific values in an array of objects in JavaScript?

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 08:55:15

13K+ Views

Let’s say the following is our array of objects −var details = [{    studentName: "John",    studentMarks: 92 }, {    studentName: "David",    studentMarks: 89 }, {    studentName: "Mike",    studentMarks: 98 }, ];To get only specific values in an array of objects in JavaScript, use the ... Read More

How to add a new object into a JavaScript array after map and check condition?

AmitDiwan

AmitDiwan

Updated on 12-Sep-2020 08:54:09

440 Views

For this, you can use filter() along with map().Exampleconst details =[    { customerName: 'John', customerCountryName: 'UK', isMarried :true },    { customerName: 'David', customerCountryName: 'AUS', isMarried :false },    { customerName: 'Mike', customerCountryName: 'US', isMarried :false } ] let tempObject = details.filter(obj=> obj.isMarried == true); tempObject["customerNameWithIsMarriedFalse"] = details.filter(obj => ... Read More

Advertisements