简体   繁体   中英

How do I get the first object's property which is color? How do we basically deal with an array of objects in JavaScript or Typescript

This is the array that I have but I have no Idea how to access the first object's individual properties.

let cars = [
  {
    "color": "purple",
    "type": "minivan",
    "registration": new Date('2017-01-03'),
    "capacity": 7
  },
  {
    "color": "red",
    "type": "station wagon",
    "registration": new Date('2018-03-03'),
    "capacity": 5
  }]
console.log(cars[0].color)
>>> "purple"

Try the MDN js docs to learn the basics https://developer.mozilla.org/en-US/docs/Web/JavaScript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM