简体   繁体   English

深入研究 Javascript 阵列的特定索引

[英]Digging Into Specific Index Of Javascript Array

new to Javascript and having a hard time understanding some data manipulation. Javascript 的新手,很难理解一些数据操作。

I'm pulling over some data from a var from PHP to JS and cannot figure out how this is indexed!我正在从 PHP 到 JS 的 var 中提取一些数据,但无法弄清楚这是如何索引的! Any help is greatly appreciated!!任何帮助是极大的赞赏!!

$heretimePh1 = "{rate:958.741566}, {rate:958.741566}, {rate:958.741566}, {rate:958.741566}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:5000}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7669.932528}, {rate:7465.172304}, "

Here is my code for trying to create a var for the first value of 958.741566这是我尝试为第一个值 958.741566 创建 var 的代码

var a = <?php echo $heretimePh1; ?>;
var b = a['rate'];
var c = b[0];

But that does not seem to be working out at all, any pointers in the right direction much appreciated, unsure what I'm missing as most documentation is what seems to be the usual []但这似乎根本不起作用,任何指向正确方向的指针都非常感谢,不确定我缺少什么,因为大多数文档似乎是通常的 []

To close out this question, the data coming from the PHP var $heretimePh1 was a string, even though it had multiple values and,'s from a mysql query using PHP gettype showed it was NOT an array and was a string.为了结束这个问题,来自 PHP var $heretimePh1的数据是一个字符串,即使它有多个值,并且来自使用gettype的 mysql 查询,它是一个字符串。 Using the PHP function explode(",", $heretimePh1);使用 PHP function explode(",", $heretimePh1); I was able to get was I was looking for.我能够得到是我正在寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM