Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

52
Views
Currently learning svelte and need some assistance

Currently I am trying to create a hacker news clone (not from the example given on website). Currently I made an api call that returns an array but I can't seem to get rid of the square brackets. For reference my code is below

onMount(() => {
    fetch('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty&limitToFirst=10&orderBy="$key"')
        .then((res) => {
            return res.text();
        })
        .then((text) => {
            items = text.split(",");
            setTimeout(3000);
            data = items.filter((val) => {
                return val.replace(/[\[\]']+/g, "");
            });
        });
    //console.log(data);
    //getData(items).then(console.log);
});

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The API provides a JSON object, but you read it as text (res.text()). Replace this with res.json() and the result will automatically be parsed to an array of IDs.

There is no need to manipulate JSON in string form, just parse it/let it be parsed.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!