Pulling data from array into new independent variables - JavaScript?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

For this, you can use the dot(.) notation.

Example

Following is the code −

const employeeDetails = [
   {
      employeeName: "Chris",
      employeeAge: 25,
      employeeTechnology: "Java"
   },
   {
      employeeName: "David",
      employeeAge: 27,
      employeeTechnology: "Javascript"
   },
   {
      employeeName: "Bob",
      employeeAge: 24,
      employeeTechnology: "Python"
   }
]
var firstName = employeeDetails[1].employeeName;
var age = employeeDetails[1].employeeAge;
var technology = employeeDetails[1].employeeTechnology; 
console.log(firstName);
console.log(age);
console.log(technology);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo248.js.

Output

This will produce the following output on console −

PS C:\Users\Amit\javascript-code> node demo248.js
David
27
Javascript
raja
Updated on 09-Nov-2020 06:30:11

Advertisements