Getting data synchronously using map and dataservice

I’m trying to map through some data, and call dataservice with the data. The problem is, i give the dataservice mapped data ID in order, but I received them differently, because the response time for both ID are different. Example:

// forms = [3, 133], index) => {
        // I give the ID's like this - 3, 133
        dataService.getApplianceModelData(formId).then((data) => {
        // I receive the data like this - [133 data], [3 data]

I thought the map method is synchronous, but i receive the data asynchronouosly? The dataservices that is called:

  async getApplianceModelData(id) {
    const { data } = await axios.get(
      "/api/1/hardware/appliance_models/" + id + "/",
    return data;

I want to get data like i input it (synchronous), if i map through 3, 133, i want to get first 3 data, and then 133 data. Any advice?


it would help you post the full issue and what you have? that should help understand what you are really trying to do.

for what it’s worth,

... (formId, index) => {
  // I give the ID's like this - 3, 133
  const data = await dataService.getApplianceModelData(formId)
  // I receive the data like this - [133 data], [3 data]

may help preserve your order. Because with what you currently have, it’s tempting to think that your .map would wait between executions, but that’s not going to be the case because when dataService.getApplianceModelData(formId) is called, it just proceeds to the next thing (while that promise resolves in the .then block

If you do need the values returned from the array you would likely need to have a something that looks like = await Promise.all( ...