#Basic TypeScript

19 messages · Page 1 of 1 (latest)

crisp wigeon
#

I wanna store values in array but I wanna take up a simple and efficient approach
problem: I get data every second from server in the form
[{obj1},{obj2},...] every object is of form

{
  bus_number: 1,
  cur_lat:1.00,
  cur_long:1.00,
}

I wanna store every bus number in separate array bus_number may be any string

finally I need all the cur_lat and cur_long of each bus in array

fierce imp
#

depends, do you want to store duplicates or not?

#

do you always want to store the latest update?

crisp wigeon
#

what duplicates?

#

na I wanna store the whole data

fierce imp
#

what if you recieve

[{
  bus_number: 1,
  cur_lat:1.00,
  cur_long:1.00,
},
{
  bus_number: 1,
  cur_lat:1.00,
  cur_long:1.00,
}]

?

#

the same bus number?

crisp wigeon
fierce imp
#

also, how are you planning to access the elements?

crisp wigeon
#

as bus_number is primary key in db

fierce imp
#

display them all in a loop?
only need to display one by bus number?

crisp wigeon
fierce imp
#

would use a Set<string, Array<{ lon: number, lat: number }>>

#

that way, you can easily access the bus by it's number

#

and then all its positions in order

crisp wigeon
crisp wigeon
fierce imp
#

!resolved