0

I have this hash

data = {"05 INTERNAL":[["5e Research","66"]],"06 MISCELLANEOUS":[["6a Internal Training","69"]]}

I want to get the value of the first key in the array. when I do

Object.values(data)[0]

I get an array which consists of

[["5e Research","66"]]

How do I extract the value "66" from this using jquery?

Thanks for the help!

2
  • 3
    Object.values(data)[0][0][1] Commented Sep 26, 2017 at 20:42
  • That's not a hash it's a map. A "hashMap" is one particular way to implement a map, but not all maps are hashmaps. (...) and what's with [["5e Research","66"]] - that is an Array with one element: an Array of two strings. Why not just a single level ["5e Research","66"] ? Commented Sep 26, 2017 at 20:50

2 Answers 2

2

You can reference a property with string, like that:

const data = {
  "05 INTERNAL": [
    ["5e Research", "66"]
  ],
  "06 MISCELLANEOUS": [
    ["6a Internal Training", "69"]
  ]
}

console.log(data['05 INTERNAL'][0][1])

Sign up to request clarification or add additional context in comments.

Comments

1
var data = {"05 INTERNAL":[["5e Research","66"]],"06 MISCELLANEOUS":[["6a Internal Training","69"]]};

The answer is:

data['05 INTERNAL'][0][1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.