Vue data not re-rendering

When app loads it showing static data I set in seleceted, and when I change option in change the country byDay and when i fetch data I am pushing data into arrays. at start it show right data, but when I change select it console right arrays but not showing it on screen.

<template>
  <select 
  @change="changeCountry"
   v-model="selected">
    <option value="0">Select a Country</option>
    <option v-for="country in countries" :value="country.ID">
      {{ country.Country }}
    </option>
  </select>
  <div class="container">
    <h2>Positive</h2>
    <div v-for="confirmed in arrConfirmed" :value="confirmed.ID">
      {{confirmed.date}} - {{confirmed.total}}
    </div>
  </div>
</template>
<script>
import Chart from '@/components/Chart.vue';
import axios from 'axios';
import moment from 'moment';
export default {
  name: 'CountrySelect',
  componens:{
    Chart
  },
  props: ['countries'],
  data() {
    return {
      selected: '4475684d-c089-4f3e-8b09-d15156bc663a',
      byDay:{},
      arrConfirmed:[],
      arrDeaths:[],
      arrRecovered:[],
      arrActive:[],
      chartOptions:{
        responsive: true,
        maintainAspectRatio: false,
      },
      contryByDay:{},
      name: 'croatia',
    };
  },
methods: {
  changeCountry() {
    const country = this.countries.find((item) => item.ID === this.selected);
    this.name = country.Country.replace(/s+/g, '-').toLowerCase();
    this.$emit('get-country', country);
    this.updateByDay()
  },
  async fetchCovidDataByDay(){
    const res = await fetch(`https://api.covid19api.com/live/country/${this.name}/status/confirmed`);
    const data = await res.json();
    data.forEach(item =>{
      const date = item.Date;
      const {
        Confirmed,
        Deaths,
        Recovered,
        Active
      } = item;

      this.arrConfirmed.push({date, total: Confirmed})
      this.arrDeaths.push({date, total: Deaths})
      this.arrRecovered.push({date, total: Recovered})
      this.arrActive.push({date, total: Active})
      console.log(this.arrActive)
    })
    return data;
  },
  async updateByDay () {
    const data = await this.fetchCovidDataByDay();
    this.byDay = data;
    console.log(this.byDay);
  }
},
created() {
  this.updateByDay()
}
};
</script>

Change file type xls to xlsx REACTJS

i’m using this lib for my ReactApp
https://github.com/zsusac/ReactHTMLTableToExcel

in this library have this function:

handleDownload() {
    if (!document) {
      if (process.env.NODE_ENV !== 'production') {
        console.error('Failed to access document object');
      }

      return null;
    }

    if (document.getElementById(this.props.table).nodeType !== 1 || document.getElementById(this.props.table).nodeName !== 'TABLE') {
      if (process.env.NODE_ENV !== 'production') {
        console.error('Provided table property is not html table element');
      }

      return null;
    }

    const table = document.getElementById(this.props.table).outerHTML;
    const sheet = String(this.props.sheet);
    const filename = `${String(this.props.filename)}.xls`;

    const uri = 'data:application/vnd.ms-excel;base64,';
    const template =
      '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-mic' +
      'rosoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta cha' +
      'rset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:Exce' +
      'lWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>' +
      '</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></' +
      'xml><![endif]--></head><body>{table}</body></html>';

    const context = {
      worksheet: sheet || 'Worksheet',
      table,
    };

    // If IE11
    if (window.navigator.msSaveOrOpenBlob) {
      const fileData = [
        `${'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-mic' + 'rosoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><meta cha' + 'rset="UTF-8"><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:Exce' + 'lWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/>' + '</x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></' + 'xml><![endif]--></head><body>'}${table}</body></html>`,
      ];
      const blobObject = new Blob(fileData);
      document.getElementById('react-html-table-to-excel').click()(() => {
        window.navigator.msSaveOrOpenBlob(blobObject, filename);
      });

      return true;
    }

    const element = window.document.createElement('a');
    element.href =
      uri +
      ReactHTMLTableToExcel.base64(
        ReactHTMLTableToExcel.format(template, context),
      );
    element.download = filename;
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);

    return true;
  }

that one make a xls file, but i need a xlsx file, but i don’t know how to change that, i tryied a lot of things, but no solution =[

theres a similar code here:
https://stackblitz.com/edit/react-custom-html-table-to-excel?file=index.js

i already used that format like that to remove one column, but i can’t do the same thing for file name, anyone can help me please?

Trying to generate a random movie from TMDB, doesn’t seem to work properly, and I’m not sure why. Written in JS / HTML

I have tried using a debugger in the displayMovieInformation function and it doesnt seem to even get to that point. When you click the button nothing happens, no errors, nothing. Not sure whats going on. If anyone has any ideas on what I could try, or if im just dumb and missed something extremely obvious please let me know! Thanks 🙂

// Variables needed

const movieGenre = document.querySelector(".genreOption");
const movieYear = document.querySelector(".yearOption");
const movieSorting = document.querySelector(".sortOption");
const movieApiKey = "2e23590ce3564e605ddd23163743fd00";

// Call to add the year and genre to the options for user select
yearsToUserSelect();
genreToUserSelect();

//Event listener for the generate random movie button

document
  .querySelector(".generateMovie")
  .addEventListener("click", generateRandomMovie);

//Adding the years and genre from the api to the select options for user to choose from
function yearsToUserSelect() {
  let startYear = new Date().getFullYear();
  for (let index = startYear; index >= startYear - 50; index--) {
    let option = document.createElement("option");
    option.value = index + "&";
    option.textContent = index;
    document.querySelector(".yearOption").appendChild(option);
  }
}

function genreToUserSelect() {
  genreListApi().then((genres) => {
    genres.genres.forEach((genre) => {
      let option = document.createElement("option");
      option.value = `${genre.id}&`;
      option.textContent = genre.name;
      document.querySelector(".genreOption").appendChild(option);
    });
  });
}

// Function for getting the movies

async function getMoviesList(movieGenre, movieYear, movieSort, moviePage = 1) {
  //disable the button
  document.querySelector(".generateMovie").disabled = true;
  //add the chosen options into the api
  let response = `https://api.themoviedb.org/3/discover/movie?sort_by=${movieSort}${
    movieYear != "All" ? "&primary_release_year=" + movieYear : ""
  }${
    movieGenre != "All" ? "with_genres=" + movieGenre : ""
  }api_key=2e23590ce3564e605ddd23163743fd00&page=${moviePage}`;
  let foundMovies = await fetch(response);
  foundMovies = await foundMovies.json();
  //return the button to on so that the user can generate another movie
  document.querySelector(".generateMovie").disabled = false;
  return foundMovies;
}

//Function for generating the random movie

function generateRandomMovie() {
  let randomMovieIndex;
  // First request to figure out how many options per page
  getMoviesList(movieGenre.value, movieYear.value, movieSorting.value).then(
    (value) => {
      if (value.moviePage == 1) {
        //Now we randomize it
        getMoviesList(
          movieGenre.value,
          movieYear.value,
          movieSorting.value,
          Math.floor(
            Math.random() * (value.total_pages > 500 ? 500 : value.total_pages)
          ) + 1
        )
          .then((value) => {
            //Choose a random movie in the array
            randomMovieIndex =
              Math.floor(Math.random() * value.results.length - 1) + 1;
            //send all the information to another function that will then display the information
            displayMovieInformation(
              value.results[randomMovieIndex].poster_path,
              value.results[randomMovieIndex].title,
              value.results[randomMovieIndex].overview,
              value.results[randomMovieIndex].release_date,
              value.results[randomMovieIndex].original_language,
              value.results[randomMovieIndex].vote_average,
              value.results[randomMovieIndex].popularity,
              value.results[randomMovieIndex].genre_ids
            );
          })
          .catch((reason) => {
            console.log("error: " + reason);
            document.querySelector(".generateMovie").disabled = false;
          });
      }
    }
  );
}

// Find genre name and ID from the api
async function genreListApi() {
  let genres = await fetch(
    "https://api.themoviedb.org/3/genre/movie/list?api_key=" +
      movieApiKey +
      "&language=en-US"
  );
  genres = await genres.json();
  console.log("Checking genres", genres);
  return genres;
}

function displayMovieInformation(
  poster_link,
  title,
  // overview,
  // release_date,
  // language,
  // vote,
  popularity,
  genres = []
) {
  genreListApi().then((userGenre) => {
    userGenre = userGenre.genres;
    let chosenGenreName = "";
    //to check the genres name with genre id
    console.log("Checking genres", genres);
    genres.forEach((element) => {
      userGenre.forEach((genreID) => {
        if (element == genreID.id) chosenGenreName += `${genreID.name},  `;
      });
    });
    //add information like movie name, photo, overview and etc
    document.querySelector(".movieInformation").innerHTML = `        
    <div class="chosenMovieInformation">
      <p class="text">
        <span
          >Movie Title: </span
        >${title}
      </p>
    <div class="movieImageContainer">
    <img
      src="${
        poster_link ? "https://image.tmdb.org/t/p/original" + poster_link : ""
      }"
      class="movieImage"
      alt="This is a poster of the currently chosen movie."
    />
  </div>
    <p class="text">
    <span
      >Movie Genre: </span
    >${chosenGenreName}
  </p>
    <p class="text">
    <span
      >Movie Popularity: </span
    >${popularity}
  </p>
  </div>
`;
  });
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="./assets/css/style.css" />
    <title>Eat Drink Relax</title>
  </head>
  <body>
    <!-- Header / Jumbotron -->

    <!-- Nav bar? Holds the randomize all button, and the favorites button (bring to new page) -->

    <!-- Eat card? Holds the name of the food, image and a randomize button. -->

    <!-- Drink card? Holds the name of the drink, image and a randomize button. -->

    <!-- Movie card? Holds the name of the movie, image and a randomize button. -->

    <div class="container">
      <div class="movieInformation"></div>
      <div class="movieOptions">    
        <div class="option">
          <p>GENRE:</p>
          <select class="genreOption">
            <option value="All">All</option>
          </select>
        </div>
        <div class="option">
          <p>YEAR:</p>
          <select class="yearOption">
            <option value="All">All</option>
          </select>
        </div>
        <div class="option">
          <p>SORT:</p>
          <select class="sortOption">
            <option value="popularity.desc&">Most Popular</option>
            <option value="popularity.asc&">Least Popular</option>
            <option value="primary_release_date.desc&">Latest</option>
            <option value="primary_release_date.asc&">Oldest</option>
            <option value="vote_average.desc&">Top Rated</option>
            <option value="vote_average.asc&">Least Rated</option>
          </select>
        </div>
        <button class="generateMovie">Randomize Movie</button>
      </div>
    </div>

    <!-- Footer? Do we want a footer? Or just leave it blank? -->

    <script src="./assets/js/script.js"></script>
  </body>
</html>

React-Typescript – Mapping props with dictionary type

I have been using Typescript with React from a while. I have a scenario where my type definition is similar to this

type Attributes: {
 industries: [];
 regions: [];
 products: [];
 [key: string]: [];
}

The top three props are consistent while the last one can be areaTypes or categories.

Now when I map through these props I can read the data of the top three props as their names are consistent but when I want the value for the dictionary prop I have to give the name of that specific prop in order to read it.

<ul>
  {props.areaTypes.map((item) => (
    <li>{item}</li>
  ))}
</ul>

I want to know if there is any other efficient way to read values of dictionary type, so I don’t have to type in the name of the unknown props each time to map it.

Function firing twice on click in React component

TL/DR: My simple toggle function fires twice when button is clicked.

I’m using useEffect in a React (w/ Next.js) component so that I can target the :root <html> tag for which I need the class to be toggled. The code is the following:

useEffect(() => {
   const toggleMode = () => {
      const root = document.documentElement;
          
      root.classList.toggle("dark");
      console.log("click");
   };

const toggleBtn = document.querySelector("#toggle-btn");

toggleBtn.addEventListener("click", toggleMode);

I have the necessary imports, the code is placed inside the main component function before the return, and there’s no errors in the console at all.

The only issue is that the function is fired twice every time the button is clicked and I cannot find any reason why or solutions online.

Would really appreciate your help and please let me know if I’m missing any information.

Cheers!

Mongoose aggregation $lookup returns empty array in ‘as’ field

Let’s say we have two collections: Orders and Sellers for an Ebay like business where customers can order items from individual sellers.

Each Order contains a seller field which lists the ID of the shop owner.

const orderSchema = new mongoose.Schema({
  seller: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'Seller' },
  item: { type: String },
});

const Order = mongoose.model('Order', orderSchema);

When I try to use $lookup

  const aggregateOrdersWithSellerInfo = await Order.aggregate([
    {
      $lookup: {
        from: 'seller',
        localField: '_id',
        foreignField: 'seller',
        as: 'seller_info',
      },
    },
  ]).exec();

all seller_info fields (ex: aggregateOrdersWithSellerInfo[0].seller_info) return an empty array:

> (0) []

But I would expect it to return the seller associated with the seller field on each Order such as:

{
   "_id":"62aa2858699a752a083bf100",
   "firstName":"Nikki",
   "__v":0
}

How to get the associated seller document using aggregation?

Full Code

const mongoose = require('mongoose');

const connect = async (dsn) =>
  mongoose.connect(dsn, {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  });

// Order Schema

const orderSchema = new mongoose.Schema({
  seller: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'Seller' },
  item: { type: String },
});

const Order = mongoose.model('Order', orderSchema);

// Seller Schema
const sellerSchema = new mongoose.Schema({
  firstName: { type: String },
});

const Seller = mongoose.model('Seller', sellerSchema);

// Seeder
const seedLocalDatabase = async () => {
  await connect('mongodb://127.0.0.1:27017/fakewishtender');
  await Seller.deleteMany({});

  const sellers = [
    {
      firstName: 'Nikki',
    },
    {
      firstName: 'Alice',
    },
  ];

  const sellersInsertedRes = await Seller.insertMany(sellers);

  await Order.deleteMany({});
  const orders = [
    {
      seller: sellersInsertedRes.find((seller) => seller.firstName === 'Nikki')._id,
      item: 'Mango Body Butter',
    },
    {
      seller: sellersInsertedRes.find((seller) => seller.firstName === 'Alice')._id,
      item: 'Vintage Jacket',
    },
  ];

  await Order.insertMany(orders);
};

// Aggregation
(async () => {
  await seedLocalDatabase();

  const aggregateOrdersWithSellerInfo = await Order.aggregate([
    {
      $lookup: {
        from: 'seller',
        localField: '_id',
        foreignField: 'seller',
        as: 'seller_info',
      },
    },
  ]).exec();

  const allSellers = await Seller.find({});
  const allOrders = await Order.find({});

  const sellersWithOrders = allOrders.map((order) =>
    allSellers.filter((seller) => seller._id.toJSON() === order.seller.toJSON())
  );
  const sellersPopulatedWithAggregate = aggregateOrdersWithSellerInfo.map(
    (order) => order.seller_info
  );

  console.log(
    `
    
    Sellers populated with aggregation are: 
    
    ${JSON.stringify(sellersPopulatedWithAggregate)}
    
    `
  );
  console.log(
    `But I would expect sellers populated with aggregation to be: 
    
    ${JSON.stringify(sellersWithOrders)}
    
    `
  );
  mongoose.disconnect();
})();

Javascript – autocomplete search for names

I want to add autocomplete feature to my retail product app – similar to google/youtube search’s autocomplete.

My backend stack is spring boot.

There are a million different products in the database.

Below are my thoughts:

  1. create an array and fetch the names while loading the screen -> ( seems overkill for a million records)
  2. wait for 2 or 3 characters and do a backend search with filter -> wont be fast enough.

How does google/youtube achieve this ? the results are instantaneous without any backend calls

React router: How to back-navigate a user to a different page than they were previously on?

The problem I’m facing is that when a user clicks on a custom back button on my web page, I want it to navigate the user to a different page than they were previously on.

For example, a user is browsing around on www.mywebpage.com/. The user then clicks on a link to go to www.mywebpage.com/foo/bar. When the user clicks on the back button, I would like to back-navigate them to www.mywebpage.com/foo.

How can I achieve this with react router? Preferably using the hooks method or whatever is best.

I’m currently using react-router v5.

Html Inserting Map

I am trying to make a website for my lawn mowing business. I want to add a feature that allows the user to type in their address into a search bar and come up with a result telling them if their address is available for lawn moving service.
Example: “1234 Example St Example city” into a search bar and showing a green area of supported houses and telling the user if it is available or not. I am using HTML, CSS, and JavaScript. How do i make this happen?

Late timing of `Date().getTime()`?

I’m trying to get the timing of a user’s click on a dynamically-generated image using Shiny and some Javascript. The app below reports the client’s time as LATER than the time captured within the server, which is not desired. I’d like to capture the time given by the user’s browser when they click on the image (this will prevent noise and delays from the trip from the client to the Shiny server). Any ideas?

library(shiny)
library(shinyjs)
options(digits.secs = 3)     # Modify and save default global time options


click.time.image.js <- "

  document.getElementById('img').onclick = function(){
      var the_time = new Date().getTime();
      console.log(the_time);
      // set input$client_time to the_time:
      Shiny.setInputValue('client_time', the_time)
}
        "

shinyApp(

  ui = fluidPage(
    useShinyjs(),
    sidebarLayout(
      sidebarPanel(
        p("When clicking on the histogram, I'd like to capture the client-side computer's time"),
        actionButton(inputId="new_image", label= "New Image")
        ),
      mainPanel(
        imageOutput("img", click = "photo_click"),
        textOutput("client_time"),
        textOutput("server_time")
      )
    )
  ),
  server = function(input, output) {

    output$img <- renderImage({
      input$new_image

      outfile <- tempfile(fileext='.png')
      png(outfile, width=400, height=400)
      hist(rnorm(100))
      dev.off()

      shinyjs::runjs(click.time.image.js)

      list(src = outfile,
           alt = "This is alternate text")
    },
    deleteFile = TRUE)



    output$server_time <- renderText({
      req(input$photo_click)
      server.time <- as.character(strptime(Sys.time(), "%Y-%m-%d %H:%M:%OS"))    # Time with milliseconds
      paste("SERVER TIME:", server.time)
    })

    output$client_time <- renderText({
      req(input$photo_click)
      req(input$client_time)
      client.time <- input$client_time    # Time with milliseconds
      client.time <- as.POSIXct(client.time/1000, origin="1970-01-01")
      paste("CLIENTs TIME:", client.time)
    })


  }
)

Why React js receive multiple answer from server with Socket.io?

When emit a event to the websocket server, the server receive the event once and send a response, but the client receive the event multiple time:
result expected
result received
client side:

client.emit("test", {
  room: props.room,
});
client.on("testResponse", () => {
  console.log("test response app");
});

server side :

 socket.on("test", (data: { room: string }) => {
console.log("test");
io.in(data.room).emit("testResponse", {});
});

How to filter through this json file to get station names for those whose air temperature is 30 or 40

//This is a nested json and I want to filter and get the station names for a specific air temp value    

[
      {
         {
            "station": [
              {
                "station_code": "AGROS",
                "station_latitude": "34.9148750",
                "station_longitude": "33.0156667"
              },
              
              {
                "station_code": "ATHALASSA",
                "station_latitude": "35.140957",
                "station_longitude": "33.396579"
              },
              {
                "station_code": "ATHIENOU",
                "station_latitude": "35.0502333",
                "station_longitude": "33.5423000"
              },
              {
                "station_code": "CAVO_GRECO",
                "station_latitude": "34.971012",
                "station_longitude": "34.070785"
              },
              {
                "station_code": "CYTASAT",
                "station_latitude": "34.861263",
                "station_longitude": "33.382527"
              },
              {
                "station_code": "EPTAGONEIA",
                "station_latitude": "34.8472556",
                "station_longitude": "33.1433722"
              },
              }
            ]
          },
          "observations": [
            {
              "station_code": "AGROS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "17.6",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "25.3",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "13.9",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "1.2",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.1",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "310",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Direct Solar Radiation",
                  "observation_value": "4",
                  "observation_unit": "W/m2"
                },
                {
                  "observation_name": "Global Radiation",
                  "observation_value": "1",
                  "observation_unit": "W/m2"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "31.4",
                  "observation_unit": "Celcius"
                },
               
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
               
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "1.2",
                  "observation_unit": "m/s"
                },
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "82",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "PLATANIA",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "16.9",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "24.1",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "12.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.3",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "83",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "POLIS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "26.0",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "29.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "19.7",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "1.9",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.9",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "339",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Direct Solar Radiation",
                  "observation_value": "4",
                  "observation_unit": "W/m2"
                },
                {
                  "observation_name": "Global Radiation",
                  "observation_value": "2",
                  "observation_unit": "W/m2"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "70",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                },
                {
                  "observation_name": "Atmospheric Pressure (Station Level)",
                  "observation_value": "1008.8",
                  "observation_unit": "hPa"
                },
                {
                  "observation_name": "Atmospheric Pressure (Mean Sea Level)",
                  "observation_value": "1011.5",
                  "observation_unit": "hPa"
                }
              ]
            },
            {
              "station_code": "POLYSTYPOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "18.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.3",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "1.1",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "223",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "86",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.0",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "PRODROMOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "21.7",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "12.9",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "16.1",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.0",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "0.9",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "90",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Global Radiation",
                  "observation_value": "0",
                  "observation_unit": "W/m2"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "88",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "PYRGOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "20.7",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "29.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "17.1",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "0.6",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "277",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "83",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.0",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "SAITTAS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "21.0",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "29.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "15.3",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "65",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "TEPAK",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "25.7",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "32.8",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "20.9",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "1.0",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "71",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.0",
                  "observation_unit": "mm"
                },
                {
                  "observation_name": "Accumulated Rainfall (24 hours)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "TRIPILOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "17.1",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "26.8",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "13.6",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "5.5",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "21",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "72",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.00",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "TROODOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "12.9",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "19.6",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "9.5",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "3.1",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Speed (2m)",
                  "observation_value": "0.9",
                  "observation_unit": "m/s"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "320",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "75",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.0",
                  "observation_unit": "mm"
                },
                {
                  "observation_name": "Snow Depth",
                  "observation_value": "0",
                  "observation_unit": "cm"
                },
                {
                  "observation_name": "Atmospheric Pressure (Station Level)",
                  "observation_value": "827.7",
                  "observation_unit": "hPa"
                }
              ]
            },
            {
              "station_code": "VISITOR",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
                {
                  "observation_name": "Air Temperature (1.2m)",
                  "observation_value": "25.2",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Max. Temp.",
                  "observation_value": "32.7",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Extreme Day Min. Temp.",
                  "observation_value": "18.4",
                  "observation_unit": "Celcius"
                },
                {
                  "observation_name": "Wind Speed (10m)",
                  "observation_value": "3.1",
                  "observation_unit": "Knots"
                },
                {
                  "observation_name": "Wind Direction (10m)",
                  "observation_value": "297",
                  "observation_unit": "Degrees"
                },
                {
                  "observation_name": "Recom. Light Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Recom. Heavy Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Relative Humidity (1.2m)",
                  "observation_value": "65",
                  "observation_unit": "%"
                },
                {
                  "observation_name": "Accumulated Rainfall (10 min.)",
                  "observation_value": "0.0",
                  "observation_unit": "mm"
                }
              ]
            },
            {
              "station_code": "XYLIATOS",
              "date_time": "2022-06-15 20:10 (Local Time)",
              "observation": [
             
                {
                  "observation_name": "Recom. Medium Work Load",
                  "observation_value": "100",
                  "observation_unit": "%"
                },

//This is a nested json file
{
“observation_name”: “Recom. Heavy Work Load”,
“observation_value”: “100”,
“observation_unit”: “%”
},
{
“observation_name”: “Relative Humidity (1.2m)”,
“observation_value”: “84”,
“observation_unit”: “%”
},
{
“observation_name”: “Accumulated Rainfall (10 min.)”,
“observation_value”: “0.0”,
“observation_unit”: “mm”
}
]
}
]
}
}
]

How can I remove decimal number in discord.js v13

For my command cooldown system, I used this Code:

if(!cooldowns.has(command.name)){
cooldowns.set(command.name, new Discord.Collection());
}
const current_time = Date.now();
const time_stamps = cooldowns.get(command.name);
const cooldown_amount = (command.cooldown) * 1000;
if(time_stamps.has(message.author.id)){
const expiration_time = time_stamps.get(message.author.id) + cooldown_amount;
if(current_time < expiration_time){
const time_left = (expiration_time - current_time) / 1000;
return message.reply( `${time_left.toFixed(1)}s cooldown`).then(msg => {
setTimeout(() => msg.delete(), 3000)
})
}
}
time_stamps.set(message.author.id, current_time);
setTimeout(() => time_stamps.delete(message.author.id), cooldown_amount);

That for example returns: ‘4.2s cooldown’.
I want to know how can I remove the decimal number:
‘4s cooldown’.

Notes: I am using discord.js v13 and node.js v16