Javascript 如何在react native中创建具有x y坐标的动态数组

Javascript 如何在react native中创建具有x y坐标的动态数组,javascript,arrays,loops,react-native,Javascript,Arrays,Loops,React Native,您好,朋友们,我想在JSON数组值的帮助下创建x-y坐标的动态数组,因此低于JSON值 "data": [ { "x_value": 1, "y_value": 1527116400 }, { "x_value": 43.45, "y_value": 1527030000 }, { "x_value": 43.95, "y_value": 1526943600 }, { "x_value": 43.95,

您好,朋友们,我想在JSON数组值的帮助下创建x-y坐标的动态数组,因此低于JSON值

"data": [
  {
    "x_value": 1,
    "y_value": 1527116400
  },
  {
    "x_value": 43.45,
    "y_value": 1527030000
  },
  {
    "x_value": 43.95,
    "y_value": 1526943600
  },
  {
    "x_value": 43.95,
    "y_value": 1526857200
  },
  {
    "x_value": 44.05,
    "y_value": 1526598000
  },
  {
    "x_value": 44.25,
    "y_value": 1526511600
  },
  {
    "price": 44.1,
    "y_value": 1526425200
  },
  {
    "x_value": 44.3,
    "y_value": 1526338800
  },
  {
    "x_value": 44.25,
    "y_value": 1526252400
  }

]
我的Js代码如下

var data = null;
var array_data = response.sData.chart_data;
for (let index = 0; index < chart_data.length; index++) {
    data.push({ array_data[index].x_value, y: chart_data[index].y_value });
}
当我运行上述代码时,我会收到如下错误消息:

TypeError:null不是计算“data.push”的对象


你知道我该怎么解决这个问题吗?您的所有建议都是值得欣赏的。

在您的代码中,您不能使用Array.prototype.push上的布尔值var data=null;可变的

更好的方法是使用它创建一个新数组,其结果是对调用数组中的每个元素调用提供的函数

代码示例:

[x\值:43.45,y值:43.45,y值:152703万0万{,{x值:152703万万},{x值:43.95,y值:43.95,y值:1526943600},{x值:1.x值:1,y值:1:1.1,y值:1:1.95,y值:3.0值:1:1,1.0 0值:1,1.0 0 0 0 0 0 0 0 0 0值:1,1,1.5,0值:1.5,y值:43.95,y值:1,y值:5,y值:0值:1.5,你们值:1526868685,你们值:152685,你们值:152685757575.57575757575757575万万万万万万0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u值:44.25,y_值:1526252400}]; const data=chart\u data.mapcoordinate=>{ x:坐标x_值, y:坐标y_值 }; 控制台日志数据;var data=[]:|不能对布尔变量使用Array.prototype.push