Angular.js,更新数组中的值

时间:2018-10-15 05:00:49

标签: javascript arrays angularjs datetime

这是我的数组

someArray = [

          {
              city: colombo1,
              text: 'name1',
              newArray[ date: 2018-09-29T18:30:00.000Z, discription: 'none']
          }

          {
              city: colombo2,
              text: 'name',
              newArray[ date: 2018-10-10T07:03:43.835Z, discription: 'none']
          }

      ];

我要如下更新我的阵列

someArray = [

          {
              city: colombo1,
              text: 'name1',
              newArray[ date: Sun Sep 30 2018 00:00:00 GMT+0530 (India Standard Time), discription: 'none']
          }

          {
              city: colombo2,
              text: 'name',
              newArray[ date: Wed Oct 10 2018 14:05:27 GMT+0530 (India Standard Time), discription: 'none']
          }

      ];

我尝试使用map()更新我的数组。但是我不明白这样做的逻辑。谁能帮帮我吗。谢谢

2 个答案:

答案 0 :(得分:0)

我希望newArray是一个以“日期”作为索引的数组,

for(var i=0;i<someArray.length;i++){
  someArray[i].newArray['date'] = new Date(someArray[i].newArray['date']).toString();
}

答案 1 :(得分:0)

如果要使用地图,请尝试以下操作:

var mappedArray = someArray.map(function(item){
    item.newArray['date'] = convertDate(item.newArray['date']); 
});

https://jsfiddle.net/83sqfxc0/1/