Created
January 4, 2023 04:45
-
-
Save 47ronin/84114cec7f8f1879f04856996fd148c6 to your computer and use it in GitHub Desktop.
OpenAI: Write an angular javascript function that retrieves a JSON response from an HTTPS API and stores the values in an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function retrieveJSONResponse() { | |
// create a new HttpClient | |
const http = new HttpClient(); | |
// retrieve the JSON response from the API | |
http.get('https://example.com/api/data') | |
.then(response => { | |
// store the values in an array | |
let jsonData = response.data; | |
let dataArray = []; | |
for (let i = 0; i < jsonData.length; i++) { | |
dataArray.push(jsonData[i]); | |
} | |
console.log(dataArray); | |
}) | |
.catch(err => { | |
console.error(err); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment