JSON.parse(json_string_from_php)生成奇怪的数组

JSON.parse(json_string_from_php)生成奇怪的数组

问题描述:

I'm having a bit of difficulty with transferring a JSON object from the server to the client-side javascript

I have a rows of data fetched from MySQL query stored into $result

Here's the code:

var json = '<?= json_encode($result->fetch_all()) ?>';
var word_list = JSON.parse(json);
console.log(word_list);     //index.php:23
console.log(json);          //index.php:24

This is the result in chrome console: number of arrays in the concise version and expanded version don't match

Can someone tell me:
1. Why line 23 shows length of 5 when folded, then only show length of 4 when unfolded?
2. Where did word5 go? FYI, the word that disappears changes every time I refresh.

将JSON对象从服务器传输到客户端javascript时遇到一些困难 p>

我从MySQL查询中获取了一行数据,存储到 $ result code> p>

这里是代码: p> \ n

  var json ='&lt;?= json_encode($ result-&gt; fetch_all())?&gt;'; 
var word_list = JSON.parse(json); 
console.log(word_list  );  //index.php:23
console.log(json);  //index.php:24
nn

这是Chrome控制台的结果: p>

有人可以告诉我:
1。 为什么第23行在折叠时显示5的长度,然后在展开时仅显示4的长度?
2。 word5去哪儿了? 仅供参考,每次刷新时,消失的单词都会发生变化。 p> div>

I am able to reproduce your screenshot.

screenshot

I purposely hovered over the little "i" to reveal its tooltip. It states "Object state below is captured upon first expansion.

This means that if you print the array, don't expand it, modify the array (say with a pop()) then when you expand it you will see the modified array.

Demo: JSBin

console.log logs your state of the object to the console when it is hitting the console.log while inspecting the array (or any object) shows you the current state of it.

var a = [1,2,3,4,5].map(function(){ return new String(); });
console.log(a);
a.pop();

enter image description here