Skip to content

Instantly share code, notes, and snippets.

@47ronin
Created January 4, 2023 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 47ronin/84114cec7f8f1879f04856996fd148c6 to your computer and use it in GitHub Desktop.
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
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