0

How can I extract the following value of the variable Test? "test_bookmarks", "Janice Scott", "Birmingham all" from the javascript object into another variable?

The image comes from the console log of Google Chrome.

enter image description here

Bombo
  • 137
  • 1
  • 1
  • 10

3 Answers3

1
let states = e.$$state.value;
let labels = states.map(state => state.label); //[ 'test_bookmarks', 'Janice Scott', 'Birmingham_bil' ]
LMokrane
  • 826
  • 6
  • 15
1
for (var i=0; i<=e["$$state"].value.length-1; i++) {
    var obj = e["$$state"].value[i];
    console.log(obj.label);
}
Rehmat
  • 2,121
  • 2
  • 24
  • 28
1

If you see the value of "value" key, it tells you that it is an array. That means the if you do something like:

$$state.value[*].label

here * stands for any integer, this way you'll get the values of the label property.

So, if you want to access the first label then it would be like:

$$state.value[0].label

this will give you "test_bookmarks".

Neeraj Wadhwa
  • 645
  • 2
  • 7
  • 18