将数据从数组中提取到新的自变量中-JavaScript?
为此,可以使用点(。)表示法。
示例
以下是代码-
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