Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Nested Data Structures


 1   Array values are accessed by their index in the array in square brackets
 2   Object values are accessed by their property (key) names using dot notation
 
 If you can easily identify an array (enclosed in [square brackets]) and 
 an object (enclosed in {curly braces}), as well as remember the 
 two key points above, you'll find it quite easy to navigate nested 
 data structures. Here is a complex one repesenting a company with their 
 financial statements for example:
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 let company = {
  name: 'Apple, Inc',
  founded: 1976,
  financials: {
    incomeStatement: {
      years: [2020, 2019, 2018],
      revenue: [125, 120, 115],
      costs: [100, 100, 100],
      profit: [25, 20, 15]
    },
    balanceSheet: {
      years: [2020, 2019, 2018],
      assets: [200, 190, 180],
      liabilties: [100, 95, 90],
      equity: [100, 95, 90]
    },
    cashFlow: {
      years: [2020, 2019, 2018],
      operating: [75, 65, 55],
      investing: [22, 20, 18],
      financing: [-94, -80, -75]    
    }
  },
  competitors: ['Microsoft', 'Amazon', 'Samsung']
}

console.log(company.name);
console.log(company.competitors);
console.log(company.competitors[0]);
console.log(company.financials.incomeStatement.years);
console.log(company.financials.incomeStatement.revenue[0]);
Comment

PREVIOUS NEXT
Code Example
Javascript :: GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN" electronjs 
Javascript :: Parents, Children & Siblings 
Javascript :: regular expression for twitter embedded tweets 
Javascript :: react native red Triangle Down 
Javascript :: change user agent in playwright 
Javascript :: regex generator 
Javascript :: angular 8 on mouseover 
Javascript :: js shufflin 
Javascript :: How do you convert VARCHAR to TIMESTAMP 
Javascript :: encrypt and decrypt in js 
Javascript :: how to print an array inside another array in react 
Javascript :: how i change background of row in javascript jquery 
Javascript :: react document documentMode not found 
Javascript :: 2495016599 
Javascript :: Line logger 
Javascript :: jquery maximum value of an element by class 
Javascript :: AJAX XML - update new live data and prevent returning old chache data 
Javascript :: getelementbyid without the <script 
Javascript :: js collection 
Javascript :: Using DOM Nodes As Keys 
Javascript :: como usar for js 
Javascript :: remove object id from the specific id 
Javascript :: how to check a user is using wifi or cellular data in php 
Javascript :: pass image as props vue vuetify 
Javascript :: Arr::flatten() The Arr::flatten method flattens a multi-dimensional array into a single level array: 
Javascript :: jquery timeout 
Javascript :: How do you remove property name from this code? const foo = { name; “albert” }; 
Javascript :: override submit button javascript 
Javascript :: nodejs s3 read 
Javascript :: a7aad 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =