1

I have state with

data: [
  { 'keya': 'Quando analisa','index':0 },
  { 'keyb': 'Modelo de texto','index':1 },
  { 'keyc': 'Parte sofreu alteraes','index':2 },
  { 'keyd': 'Todos os geradores','index':3 },
],

Want to access index. Tried

this.state.data.index

but not getting index value. How to access index?

1
  • 1
    Have you tried this.state.data[index]? Commented Jul 10, 2018 at 13:09

1 Answer 1

2

Your this.state.data is a array so you either need to loop through the array to get the index value and use it to access all the objects with index property like:

for(var i=0; i<this.state.data.length; i++){
  console.log(this.state.data[i].index);
}

Or you need to explicitly define the index value as this.state.data[0].index to get the index value of object at index 0 and so on.

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

2 Comments

@ShibinRajuMathew glad to help
use map instead of for loop

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.