[英]in Javascript how do i target an array entry with "push" function?
i've been struggling with this, would appreciate help.我一直在努力解决这个问题,希望得到帮助。
i'm looking to update the value of "v.low" to like 6000 (manually) outside of the loop at the last index position in the array (last index = latest timestamp, so its current time).我希望在数组的最后一个索引位置(最后一个索引 = 最新时间戳,所以它的当前时间)在循环外将“v.low”的值更新为 6000(手动)。 But i can't target the entry properly in the array with JS.但是我无法使用 JS 在数组中正确定位条目。
here is an example - but the below is sitting in a loop where "v" is associated to the row in array这是一个例子 - 但下面是一个循环,其中“v”与数组中的行相关联
chartList[container]['option'].series[0].data.push([
v.open,
v.close,
v.low, ----< want to update its value here to 6000
v.high
]);
//i'm trying it this way, but its obviously wrong, want to update low @ last index position //我正在尝试这种方式,但显然是错误的,想要更新低@最后一个索引位置
chartList[container]['option'].series[0].data[ arraylength-1 ].low=6000; chartList[container]['option'].series[0].data[ arraylength-1 ] .low =6000; ----> also tried this: chartList[container]['option'].series[0].data[ arraylength-1 ].push('low',6000); ----> 也试过这个:chartList[container]['option'].series[0].data[ arraylength-1 ].push('low',6000);
//i essentially want to update the value of "low" at the last index in array "chartList[container]['option'].series[0].data" //我本质上想更新数组“chartList[container]['option'].series[0].data”中最后一个索引处的“low”值
Here is the code这是代码
// List all data candle
$.each(dataParsed.candles, function(k, v){ vListChart.push(v.close); });
if(jQuery.inArray(dataParsed.candles[dataParsed.candles.length - 1].date, chartList[container]['option'].xAxis[0].data) === -1){
// showAlert('we have new data');
chartList[container]['option'].series[0].data = chartList[container]['option'].series[0].data.slice(0, -4);
chartList[container]['option'].series[1].data = chartList[container]['option'].series[1].data.slice(0, -4);
chartList[container]['option'].xAxis[0].data = chartList[container]['option'].xAxis[0].data.slice(0, -4);
chartList[container]['data_candles'] = chartList[container]['data_candles'].slice(0, -4);
chartList[container]['data_candles'] = $.merge(chartList[container]['data_candles'], dataParsed.candles);
chartList[container]['data'] = chartList[container]['data'].slice(0, -4);
chartList[container]['data'] = $.merge(chartList[container]['data'], vListChart);
$.each(dataParsed.candles, function(k, v){
chartList[container]['option'].xAxis[0].data.push(v.date);
chartList[container]['option'].series[0].data.push([
v.open,
v.close,
v.low,
v.high
]);
if(k == dataParsed.candles.length - 1){
chartList[container]['option'].series[1].data.push(v.open);
} else {
chartList[container]['option'].series[1].data.push(v.close);
}
});
/// this is the candle formation /// 这是蜡烛的形成
echo json_encode([
'error' => 0,
'candles' => $listCandles,
'current_price' => $Coin->_getPrice(),
'notification_list' => $listNotification,
'order_list' => $listOrder,
'internal_order' => $internalOrderList,
'currency' => $CryptoApi->_getCurrency()
]);
chartList[container]['option'].series[0].data[ arraylength-1 ][2]=6000
请注意,这不会影响 v 引用的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.