Passing arguments into map()

2442 views javascript
9

I am trying to use the map() function on an Array that returns some elements using puppeteer

The below is the code

let res = await page.evaluate(

  elementPath => {

    return Array.from(document.querySelectorAll(elementPath)).map(

      (cin, index) => {

        return {

          cinemaState: null,

          cinemaIndex: index,

          cinemaId: cin.getAttribute("data-id"),

          cinemaName: cin.getAttribute("data-name"),

          cinemaURL: cin.getAttribute("data-url")

        };

      },

      { s: "NSW" }

    );

  },

  `div[data-state=${cinemaState}] div.top-select-option a.eccheckbox`,

  cinemaState

);

I am not able to assign **cinemaState with variable s or cs. Wondering what I could be missing here

answered question

1 Answer

0

[1,2,3,4].map(function(num, index,wholeArray){
    console.log(num,index,wholeArray,this.s);
},{s:"nsw"})

maps takes two argument callback and thisArg whatever u will pass at the second arg will be accessible bi this

posted this

Have an answer?

JD

Please login first before posting an answer.