Skip to content
Advertisement

Node js javascript group json array to the sub arrays and put data in hour interval

Hi I have a json data where i have multiple entries recorded with the timestamp. i want to filter the records and make a new sub array that will group all the entries with an hour interval.

like i have the json

JavaScript

Now i want to output a new array of json with the ips grouped in time interval.

What i have done is this code

JavaScript

the code is running fine . but i dont think this is the best approach because this will run many iteration loops and i want to make it cost efficient. can anyone tell me the best possible way or can code for me ?

you can use any npm package you want.

adding fiddle for reference – https://jsfiddle.net/gku24x9m/

Advertisement

Answer

Create a map with group data by hours then convert into a a list.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement