• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • About
  • Life
  • Tech
  • Travel
  • Work
  • Questions
  • Contact

Welcome

.

Using Javascript how do I find a path to an object nested in empty arrays?

April 10, 2020 by

Questions › Using Javascript how do I find a path to an object nested in empty arrays?
0
Vote Up
Vote Down
Garmaine asked 3 years ago

I am guessing my terminology in the following post is wrong. I am generally new to using APIs.

I am using an API from the Census Bureau that returns a list of of objects in JSON format. The issue I am having with this particular API is that it appears the arrays are nested within arrays that don't have names or any way to find a path through to the object.

Here is what the API query returns:

[
[
"DRRALL",
"CRRINT",
"RESP_DATE",
"CRRALL",
"GEO_ID",
"DRRINT",
"state"
],
[
"0.4",
"37.1",
"2020-04-10",
"41.4",
"0400000US36",
"0.4",
"36"
]
]

I am trying to obtain the date the information was queried and the response rate, but I just have never see JSON in this format. I checked to make sure it is valid JSON, and it is. I tried peeling away layer by layer, but I end up with undefined or empty arrays when attempting to push it to another variable.

Here is as close as I've gotten to the desired results:


fetch(url)
  .then((resp) => {
    return resp.json();
  })

  .then((data) => {
    stateArray.push(data[1]);
  });

console.log(stateArray);

Here's the result of my console log:

[]
​0: (7) […]
​​0: "0.4"
​​1: "37.1"
​​2: "2020-04-10"
​​3: "41.4"
​​4: "0400000US36"
​​5: "0.4"
​​6: "36"
length: 7
<prototype>: Array []
length: 1

As you'll see, there is another empty array just before the array with my desired objects.

Any help would be great.

Thanks!

Are you looking for the answer?
Original Question and Possible Answers can be found on `http://stackoverflow.com`

Question Tags: api, javascript, json

Please login or Register to submit your answer




Primary Sidebar

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Newsletter

Complete the form below, and we'll send you all the latest news.

Footer

Footer Funnies

Who knew that reading the footer could be such a hilarious adventure? As we navigate websites, books, and documents, we often stumble upon the unassuming space at the bottom, only to discover a treasure trove of amusement. In this side-splitting compilation, we present 100 jokes that celebrate the unsung hero of content – the footer. Get ready to chuckle, giggle, and maybe even snort as we dive into the world of footnotes, disclaimers, and hidden comedic gems. Brace yourself for a wild ride through the footer!

Recent

  • Unveiling the Enigma: Almost-Magical Lamp Lights Highway Turns
  • The Impact of Young Onset Dementia on Employment and Finances: Optimizing Post-Diagnostic Approaches
  • 11 Wonders of 2023 Technological Breakthrough – Unveiling the Future
  • Work from Home and Stay Mentally Sane – Achieve Productivity and Well-being
  • Hidden Gems of New York City – Uncover the Must-See Treasures!

Search

Tags

Advancements architecture beautiful life best building calling city commercial convenience employment Finances Cognitive decline Future gadgets Hidden Gems highway Home houses hydration Impact Innovations lamp lighting Mental health military tech Must-See New York City occupation Productivity recreation romance sepia shopping sippy cups smartphones social Technological breakthroughs technology toddlers Treasures turns Uncover Well-being Wonders Work Young onset dementia

Copyright © 2023