Show Enemy's State and its Information By Scan

As title, here is my code.

Code:
<Before Eval>
if (target.isEnemy()) {

  var text = target.name() + '\n';
  text += '\\px[100]\\c[4]ATK:\\c[0] ' + target.atk;
  text += '\\px[300]\\c[4]MAT:\\c[0] ' + target.mat;
  text += '\n';
  text += '\\px[100]\\c[4]DEF:\\c[0] ' + target.def;
  text += '\\px[300]\\c[4]MDF:\\c[0] ' + target.mdf;
  $gameMessage.add(text);
}

// Check if target have state that id = 1~700
for (var i = 1 ; i < 700 ; i++ ) {
if (target.isStateAffected(i)) {
   var text = "X" ;
$gameMessage.add(text);

}
}

</Before Eval>

X should be state i's name, what should I replace with it?
bump :]
Try this! =)
Code:
var text = target.states()[i].name;
Edit: whoops, this assumes "i" is indexing the states on the battler rather than the states in the database. See my next post here for a correction.
Try this! =)
Code:
var text = target.states()[i].name;
Thank you! looks like I have a lot of things to learn.
Thread closed IgnoreMe
Moderator note: This thread is being re-opened as there is an error in the solution given.
@caethyril Please post your correction.
Thanks, sorry for the error. >_<

Try this instead:
Code:
var text = $dataStates[i].name;
Thanks, sorry for the error. >_<

Try this instead:
Code:
var text = $dataStates[i].name;
It's OK. Btw actually there's no different. lol

Original thread: https://forums.rpgmakerweb.com/threads/show-enemys-state-and-its-information-by-scan.91548/