I have a query regarding extracting a specific value from an array returned by Supabase.
Here is the code snippet I am using:
countries.value = parseInt(countries.value.map(({ aantal }) => aantal));
When I don't use parseInt, the number appears like this: [2000]. But when I wrap it in parseInt, I only get 2000, which is the desired output. I also tried using .toString and it worked as well.
My main concern:
Is this the correct approach? Initially, I was puzzled by why the number was enclosed in square brackets []
Below is the entire code:
<script setup>
import { ref, onMounted } from "vue";
import { supabase } from "./lib/supabaseClient";
const countries = ref();
async function getCountries() {
const { data } = await supabase.from("count").select("aantal");
countries.value = data;
console.log({ data });
countries.value = parseInt(countries.value.map(({ aantal }) => aantal));
}
async function updateplus() {
countries.value++;
console.log("update", countries.value);
const { data, error } = await supabase
.from("count")
.update({ aantal: countries.value })
.eq("id", 1)
.select();
console.log("update", { data, error });
}
onMounted(() => {
getCountries();
});
const nummber = countries.value;
</script>
<template>
<div>
{{ countries }}
{{ nummber }}
Count
</div>
<div><button @click="updateplus()">Plus 1</button></div>
</template>