Passing arguments into map()
up vote
0
down vote
favorite
I am trying to use the built in map()
function on an Array.from () that returns some elements using Puppeteer.
The below is the code:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cs: `state is ${this.s}`, // returns state is undefined
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 cs
with variable s
or cinemaState
.
Wondering if you have solution
javascript node.js google-chrome-devtools puppeteer headless-browser
add a comment |
up vote
0
down vote
favorite
I am trying to use the built in map()
function on an Array.from () that returns some elements using Puppeteer.
The below is the code:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cs: `state is ${this.s}`, // returns state is undefined
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 cs
with variable s
or cinemaState
.
Wondering if you have solution
javascript node.js google-chrome-devtools puppeteer headless-browser
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to use the built in map()
function on an Array.from () that returns some elements using Puppeteer.
The below is the code:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cs: `state is ${this.s}`, // returns state is undefined
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 cs
with variable s
or cinemaState
.
Wondering if you have solution
javascript node.js google-chrome-devtools puppeteer headless-browser
I am trying to use the built in map()
function on an Array.from () that returns some elements using Puppeteer.
The below is the code:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cs: `state is ${this.s}`, // returns state is undefined
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 cs
with variable s
or cinemaState
.
Wondering if you have solution
javascript node.js google-chrome-devtools puppeteer headless-browser
javascript node.js google-chrome-devtools puppeteer headless-browser
edited Nov 5 at 23:34
asked Nov 5 at 3:46
Theepan Thevathasasn
234
234
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
[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
add a comment |
up vote
0
down vote
You can assign s
to the cinemaState
property in your return
statement using the following method:
cinemaState: this.s,
Additionally, Array.from()
has a built-in map
function, so you should call the map
function from within Array.from()
to avoid an intermediate array:
Array.from(arrayLike, mapFn); // good
Array.from(arrayLike).map(mapFn); // bad
Lastly, you may want to use quotes around cinemaState
in your attribute selector within your template literal selector string:
[data-state="${cinemaState}"] // good
[data-state=${cinemaState}] // bad
Your final code should look something like this:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cinemaState: this.s,
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);
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basicallycs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
add a comment |
up vote
0
down vote
I am able to explain this. this is what has worked for me. I had to replace the arrow function to a traditional function
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), function (cin, index) // changed from (cin, index) =>
{
return {
cs: `state is ${this.s}`, // returns state is undefined
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);
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
[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
add a comment |
up vote
0
down vote
[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
add a comment |
up vote
0
down vote
up vote
0
down vote
[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
[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
answered Nov 5 at 3:59
Pranoy Sarkar
561311
561311
add a comment |
add a comment |
up vote
0
down vote
You can assign s
to the cinemaState
property in your return
statement using the following method:
cinemaState: this.s,
Additionally, Array.from()
has a built-in map
function, so you should call the map
function from within Array.from()
to avoid an intermediate array:
Array.from(arrayLike, mapFn); // good
Array.from(arrayLike).map(mapFn); // bad
Lastly, you may want to use quotes around cinemaState
in your attribute selector within your template literal selector string:
[data-state="${cinemaState}"] // good
[data-state=${cinemaState}] // bad
Your final code should look something like this:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cinemaState: this.s,
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);
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basicallycs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
add a comment |
up vote
0
down vote
You can assign s
to the cinemaState
property in your return
statement using the following method:
cinemaState: this.s,
Additionally, Array.from()
has a built-in map
function, so you should call the map
function from within Array.from()
to avoid an intermediate array:
Array.from(arrayLike, mapFn); // good
Array.from(arrayLike).map(mapFn); // bad
Lastly, you may want to use quotes around cinemaState
in your attribute selector within your template literal selector string:
[data-state="${cinemaState}"] // good
[data-state=${cinemaState}] // bad
Your final code should look something like this:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cinemaState: this.s,
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);
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basicallycs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
add a comment |
up vote
0
down vote
up vote
0
down vote
You can assign s
to the cinemaState
property in your return
statement using the following method:
cinemaState: this.s,
Additionally, Array.from()
has a built-in map
function, so you should call the map
function from within Array.from()
to avoid an intermediate array:
Array.from(arrayLike, mapFn); // good
Array.from(arrayLike).map(mapFn); // bad
Lastly, you may want to use quotes around cinemaState
in your attribute selector within your template literal selector string:
[data-state="${cinemaState}"] // good
[data-state=${cinemaState}] // bad
Your final code should look something like this:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cinemaState: this.s,
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);
You can assign s
to the cinemaState
property in your return
statement using the following method:
cinemaState: this.s,
Additionally, Array.from()
has a built-in map
function, so you should call the map
function from within Array.from()
to avoid an intermediate array:
Array.from(arrayLike, mapFn); // good
Array.from(arrayLike).map(mapFn); // bad
Lastly, you may want to use quotes around cinemaState
in your attribute selector within your template literal selector string:
[data-state="${cinemaState}"] // good
[data-state=${cinemaState}] // bad
Your final code should look something like this:
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), (cin, index) => {
return {
cinemaState: this.s,
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);
edited Nov 5 at 19:16
answered Nov 5 at 18:46
Grant Miller
4,681132346
4,681132346
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basicallycs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
add a comment |
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basicallycs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
This is only if you are using the lamda syntax on a single line
– C Smith
Nov 5 at 19:01
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basically
cs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
@grant-miller, Not sure I am missing something. I will update the original question with my current code.. Basically
cs:
state is ${this.s}, // returns state is undefined
– Theepan Thevathasasn
Nov 5 at 23:29
add a comment |
up vote
0
down vote
I am able to explain this. this is what has worked for me. I had to replace the arrow function to a traditional function
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), function (cin, index) // changed from (cin, index) =>
{
return {
cs: `state is ${this.s}`, // returns state is undefined
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);
add a comment |
up vote
0
down vote
I am able to explain this. this is what has worked for me. I had to replace the arrow function to a traditional function
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), function (cin, index) // changed from (cin, index) =>
{
return {
cs: `state is ${this.s}`, // returns state is undefined
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);
add a comment |
up vote
0
down vote
up vote
0
down vote
I am able to explain this. this is what has worked for me. I had to replace the arrow function to a traditional function
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), function (cin, index) // changed from (cin, index) =>
{
return {
cs: `state is ${this.s}`, // returns state is undefined
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 able to explain this. this is what has worked for me. I had to replace the arrow function to a traditional function
let res = await page.evaluate(elementPath => {
return Array.from(document.querySelectorAll(elementPath), function (cin, index) // changed from (cin, index) =>
{
return {
cs: `state is ${this.s}`, // returns state is undefined
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);
answered Nov 7 at 9:09
Theepan Thevathasasn
234
234
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53148045%2fpassing-arguments-into-map%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password