Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
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);
           } ; 
JavaScript

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

1 solution

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
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900