Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

accessing objects inside array

// Array of object
var persons = [
  {
    name: "shubham",
    age: 22,
    comments: ["Good", "Awesome"]
  },
  {
    name: "Ankit",
    age: 24,
    comments: ["Fine", "Decent"]
  },
  {
    name: "Arvind",
    age: 26,
    comments: ["Awesome", "Handsome"]
  },
  {
    name: "Ashwani",
    age: 28,
    comments: ["Very Good", "Lovely"]
  }
];

var data = persons.map(person => {
  console.log(person.name);
  console.log(person.age);
  person.comments.map((comment, index) => console.log(index + " " + comment));
});
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #accessing #objects #array
ADD COMMENT
Topic
Name
6+5 =