fetch method in javascript example

Example 1: fetch api javascript

fetch('http://example.com/songs')
	.then(response => response.json())
	.then(data => console.log(data))
	.catch(err => console.error(err));

Example 2: .fetch method

fetch('http://example.com/movies.json')
  .then(response => response.json())
  .then(data => console.log(data));

Example 3: fetch suntax

fetch('http://example.com/movies.json')
  .then((response) => {
    return response.json();
  })
  .then((data) => {
    console.log(data);
  });