Click here to Skip to main content
14,579,188 members
Rate this:
Please Sign up or sign in to vote.
See more:
let items=[];

fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
    .then(res => res.json())
    .then((result) => {
          items= result.items;
          console.log(items);
        }),
        (error) => {
            console.log(error);
           } ;  


What I have tried:

let items=[];

fetch("https://www.googleapis.com/books/v1/volumes?q=isbn:0747532699")
    .then(res => res.json())
    .then((result) => {
          items= result.items;
          console.log(items);
        }),
        (error) => {
            console.log(error);
           } ; 

		    
Posted
Updated 22-Jun-20 3:00am
Comments
Maciej Los 22-Jun-20 7:40am
   
What you mean by "normal function"?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

This is really only a useful exercise if you are converting down to ES3 e.g. for a Windows Hypertext Application. It is better to become familiar with the arrow syntax. However, if you must do it, this is how ...

1) Put the word 'function' before the parameter list,
2) If the parameter list is not in parentheses, surround the list in parentheses,
3) If the expression part after the arrow is not already enclosed in braces, enclose the expression in braces
4) Discard the arrow
5) If the expression returns a value, put 'return' in front of the final / only expression

e.g. res => res.json()
1) function res => res.json()
2) function (res) => res.json();
3) function (res) => { res.json(); }
4) function (res) { res.json(); }
5) function (res) { return res.jsoc(); }

or (result) => { items = result.items; console.log(items); }
1) function (result) => { items = result.items; console.log(items); }
2) /* not needed - parentheses already there */
3) /* not needed - braces already there */
4) function (result) { items = result.items; console.log(items); }
5) function (result) { items = result.items; return console.log(items); } // 'return' not really needed with console.log
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100