How to fetch json in JavaScript

JSON
By Jad Joubran · 
Last updated Feb 13, 2024
fetch("https://codetogo.io/api/users.json")
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(console.error);
[{
    id: 1,
    name: "Sam"
}, {
    id: 2,
    name: "Alex"
}]
Fetch API use cases on Learn JavaScript