0

Tring to iterate through Wikipedia's API call where the page keys are all unique. Creating a response, to give results that are more akin to being useful. Also working with noodl.net hence the inputs and outputs.

let resultPagesArray = Response.content.query.pages;
let resultPagesArrayEntries.entries();

// Loop
let wikiPagesArray = [];

for (let i = 0;i <resultPagesArray.length;i++) {

console.log(i);

    let obj = Noodl.Object.create ( {
        name:i.names,
        url:i.urls,
        imageUrl:i.imageUrls,
        description:i.descriptions
        });
        
    wikiPagesArray.push (obj);
}

Outputs.resultPages = resultPagesArray;

Current response:

  "batchcomplete": "",
  "continue": {
    "gsroffset": 10,
    "continue": "gsroffset||"
  },
  "query": {
    "pages": {
      "454403": {
        "pageid": 454403,
        "ns": 0,
        "title": "Deep web",
        "index": 3,
        "extract": "The deep web, invisible web, or hidden web are parts of the World Wide Web whose contents are not indexed by standard web search-engines."
      },
      "3422674": {
        "pageid": 3422674,
        "ns": 0,
        "title": "Form (HTML)",
        "index": 9,
        "extract": "A webform, web form or HTML form on a web page allows a user to enter data that is sent to a server for processing."```
  • `let resultPagesArrayEntries.entries();` is a syntax error. And `resultPagesArray` is not an array, it's an object: you need to loop it using `for (const pageId in resultPagesArray) { const i = resultPagesArray[pageId]; … }` – Bergi Jul 17 '22 at 19:33
  • Have an updated still struggling: ```// Input let searchPages = Response.content.query.pages; // Loop var p = searchPages; for (var key in p) { if (p.hasOwnProperty(key)) { let obj = Noodl.Object.create ({ id: p.pageid, name: p.title, url: p.url, imageUrl: p.imageUrls, description: p.extract }); // console.log(key + " -> " + p[key]); wikiPagesArray.push (obj); } } // Output Outputs.resultPages = obj;``` – Red Ace Jul 18 '22 at 08:30
  • Use `p[key].pageId`, `p[key].title` and so on, or a helper variable `const page = p[key]`. Also [don't use `p.hasOwnProperty(key)`](https://stackoverflow.com/a/45014721/1048572). – Bergi Jul 18 '22 at 11:08

0 Answers0