JavaScript 将数据从数组中拉到新的独立变量中
对于这一点,你可以使用dot(.)符号。
示例
以下是代码 –
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