为此,可以使用点(。)表示法。
以下是代码-
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);
要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo248.js。
输出结果
这将在控制台上产生以下输出-
PS C:\Users\Amit\javascript-code> node demo248.js David 27 Javascript