Let’s say we have records with BOTID and Name of assigned users −
let objectArray = [ { BOTID: "56", Name: "John" }, { BOTID: "57", Name: "David" }, { BOTID: "58", Name: "Sam"}, { BOTID: "59", Name: "Mike" }, { BOTID: "60", Name: "Bob" } ];
We know the array starts from index 0. If you want to access the first element from the above array, use the below syntax −
var anyVariableName=yourArrayObjectName[index].yourFieldName;
Example
let objectArray = [ { BOTID: "56", Name: "John" }, { BOTID: "57", Name: "David" }, { BOTID: "58", Name: "Sam"}, { BOTID: "59", Name: "Mike" }, { BOTID: "60", Name: "Bob" } ]; const output = objectArray[0].BOTID; console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo49.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo49.js 56