im currently trying to figure out what exactly a json file is at this point. Im stumped because instead of trying to console.log my result json, im trying to store it somewhere so I can go through it and extract the author of each post but im not sure if its an array or one big string so I dont know how to store it and go through each element to store the author into another array that will hold authors. Heres what I got so far:
console.log("Hello")
var postsArr = [];
let author = [];
let jsonPost = "";
//URI encoding here to add to the end of URL
//console.log()
let encodedSearch = encodeURIComponent(search);
console.log()
encodedSearch.replace("%20","+")
const getPosts = () => {
const urlPosts = "https://www.reddit.com/search.json?q=";
let newURL = urlPosts.concat(encodedSearch.toString().replace(/%20/g,"+"))
console.log(newURL)
return fetch(newURL)
.then(res => res.json())
.then(posts => {
jsonPost = posts
})
}
getPosts()
console.log(jsonPost)
Any help or advice is greatly appreciated!