0

I am reading a key-value from registry.It returns a javascript object as shown below,

pic

I am not able to access the value.

I tried to print the value as 
path="HKLM\\System\\CurrentControlSet\\Control\\Session Manager\\Environment";
console .log(result.path.values.USERNAME);//prints undefined
karansys
  • 2,449
  • 7
  • 40
  • 78

1 Answers1

1

Try the code below:

result[path].values.USERNAME // array syntax

In JavaScript it's not useful to use a variable as the Object's property name when you use the "regular object syntax", it will return undefined (if it doesn't have a property with the exact name of your variable):

const obj = {
  key1: 'value1',
  key2: 'value2'
}

let prop = 'key1'

// this returns undefined,
// as obj doesn't have a prop1 property
console.log('obj.prop:', obj.prop)

// this display value1, because an Object
// is an Array (under the hood), so you can
// call it's keys in an array syntax
console.log('obj[prop]:', obj[prop])

// if the prop variable gets a new value, then
// it will return a value from obj according to
// prop's new value

prop = 'key2'
console.log('prop = \'key2\':', obj[prop])

// you can use the array syntax for listing out
// the property values of an Object:
for (let key in obj) {
  console.log('iteration ' + key + ':', obj[key])
}
muka.gergely
  • 8,063
  • 2
  • 17
  • 34