Показать сообщение отдельно
  #8 (permalink)  
Старый 03.08.2022, 16:47
Аватар для ksa
ksa ksa вне форума
CacheVar
Отправить личное сообщение для ksa Посмотреть профиль Найти все сообщения от ksa
 
Регистрация: 19.08.2010
Сообщений: 14,231

Предложу такой вариант...
const data = [
    {
        "date": "2020-03-02",
        "value": "-0.00807736"
    },
    {
        "date": "2020-03-03",
        "value": "0.01775831"
    },
    {
        "date": "2020-03-04",
        "value": "0.00433390"
    },
    {
        "date": "2020-03-31",
        "value": "0.02667099"
    },
    {
        "date": "2020-04-01",
        "value": "-0.01370213"
    },
    {
        "date": "2020-04-02",
        "value": "0.02922457"
    },
    {
        "date": "2020-04-03",
        "value": "0.01015846"
    },
    {
        "date": "2020-04-06",
        "value": "0.01984755"
    },
    {
        "date": "2020-04-07",
        "value": "0.00296561"
    },
    {
        "date": "2020-04-08",
        "value": "0.01393626"
    },
    {
        "date": "2020-04-09",
        "value": "0.01132951"
    },
    {
        "date": "2020-04-10",
        "value": "-0.00822985"
    },
    {
        "date": "2020-04-13",
        "value": "-0.01640604"
    },
    {
        "date": "2020-05-04",
        "value": "-0.00000651"
    },
    {
        "date": "2020-05-05",
        "value": "-0.00000513"
    },
    {
        "date": "2020-05-06",
        "value": "-0.00501929"
    },
    {
        "date": "2020-05-07",
        "value": "0.00339571"
    },
    {
        "date": "2020-05-08",
        "value": "0.00176003"
    }
]

/*
    output
    [
        2020-03-02,
        2020-04-01,
        2020-05-04,
    ]
 */

const filtered = data => {
	const o = {}
	for (let i = 0; i < data.length; i++) {
		const m = data[i].date.slice(0, 7)
		if (o[m]) continue
		o[m] = data[i].date
	}
	return Object.values(o)
}

alert(filtered(data));
Ответить с цитированием