0

I have an object having structure

const row = { data : { name : 'hello',version : '1.2'
}};

I have function which tell what data you want

function getData (temp)
{
  // temp could be name or version
  return row.data."temp";   
}

I want result like if I call getData("name") it should result in "hello" and if call getData("version") is called it should result "1.2". In JavaScript.

  • 2
    Use bracket notation: `row.data[temp]`. – Gerardo Furtado Sep 09 '16 at 05:50
  • @harshita Just a heads up, you spelled "Assistant" wrong on your profile – 4castle Sep 09 '16 at 05:55
  • @GerardoFurtado exactly that's right i already try to suggest that one. – VjyV Sep 09 '16 at 05:55
  • This is quite basic. You may want to go back and review the tutorials and documentation you have been studying. Here's a [place to start](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors). –  Sep 09 '16 at 07:13

1 Answers1

-1

try this:

row = { data : { name : 'hello',version : '1.2'
}}

function getData (temp)
{
  return row['data'][temp] 
}
Bartłomiej Gładys
  • 4,525
  • 1
  • 14
  • 24