如何获得与一个数组相同的日期

时间:2018-09-20 03:32:15

标签: javascript

我有一个数组,

data =[{"date":"12/1/12","value":21},
       {"date":"12/2/12","value":34},
       {"date":"12/1/12","value":36},
       {"date":"12/1/12","value":32},
       {"date":"12/2/12","value":1},
       {"date":"12/2/12","value":4},
       {"date":"12/2/12","value":3},]

我需要创建另一个数组,例如从数组中检索值,

data1=[{"date":"12/1/12","value":21},
       {"date":"12/1/12","value":36},
       {"date":"12/1/12","value":32}]

data2 =[{"date":"12/2/12","value":3},
        {"date":"12/2/12","value":4},
        {"date":"12/2/12","value":1},
        {"date":"12/2/12","value":34}]

1 个答案:

答案 0 :(得分:-1)

const data1 = data.filter(datum => datum.date === ‘12/1/12’)
const data2 = data.filter(datum => datum.date === ‘12/2/12’)