mapping prop items in an array in React [duplicate]Dynamically access object property using variableHow do I check if an array includes an object in JavaScript?How to append something to an array?Is JavaScript a pass-by-reference or pass-by-value language?How to insert an item into an array at a specific index (JavaScript)?How do I loop through or enumerate a JavaScript object?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?.prop() vs .attr()For-each over an array in JavaScript?
Does Doodling or Improvising on the Piano Have Any Benefits?
Difference between shutdown options
What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?
Is there a way to play vibrato on the piano?
What is the smallest number n> 5 so that 5 ^ n ends with "3125"?
How do I Interface a PS/2 Keyboard without Modern Techniques?
How to make money from a browser who sees 5 seconds into the future of any web page?
Quoting Keynes in a lecture
Sound waves in different octaves
What is the meaning of "You've never met a graph you didn't like?"
Review your own paper in Mathematics
How much do grades matter for a future academia position?
Animation: customize bounce interpolation
What does "Scientists rise up against statistical significance" mean? (Comment in Nature)
Unable to disable Microsoft Store in domain environment
Alignment of six matrices
Is there anyway, I can have two passwords for my wi-fi
Pre-Employment Background Check With Consent For Future Checks
Do I have to know the General Relativity theory to understand the concept of inertial frame?
Why does the Persian emissary display a string of crowned skulls?
If the only attacker is removed from combat, is a creature still counted as having attacked this turn?
Storage of electrolytic capacitors - how long?
Given this phrasing in the lease, when should I pay my rent?
Ways of geometrical multiplication
mapping prop items in an array in React [duplicate]
Dynamically access object property using variableHow do I check if an array includes an object in JavaScript?How to append something to an array?Is JavaScript a pass-by-reference or pass-by-value language?How to insert an item into an array at a specific index (JavaScript)?How do I loop through or enumerate a JavaScript object?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?.prop() vs .attr()For-each over an array in JavaScript?
This question already has an answer here:
Dynamically access object property using variable
11 answers
I have an array in which I want to loop through each element and find it's value from the props which is passed to the component.
array = ['a','b','c']
I want to save the value of 'this.props.a' to a variable 'a; and similarly for other variables considering props does have the values saved , how can I do that ?
sample code :
buildURL() {
const param_array=array = ['a','b','c']
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props.param))
)
Here I need this.props.search_item , this.props.search_type , this.props.article_quality and this.props.min_views .
How can I get that?
javascript reactjs
marked as duplicate by Henry Woody, Community♦ Mar 8 at 1:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Dynamically access object property using variable
11 answers
I have an array in which I want to loop through each element and find it's value from the props which is passed to the component.
array = ['a','b','c']
I want to save the value of 'this.props.a' to a variable 'a; and similarly for other variables considering props does have the values saved , how can I do that ?
sample code :
buildURL() {
const param_array=array = ['a','b','c']
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props.param))
)
Here I need this.props.search_item , this.props.search_type , this.props.article_quality and this.props.min_views .
How can I get that?
javascript reactjs
marked as duplicate by Henry Woody, Community♦ Mar 8 at 1:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Seems like you're looking for something like lodash'spick
? lodash.com/docs/4.17.11#pick
– Strebler
Mar 7 at 3:31
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50
add a comment |
This question already has an answer here:
Dynamically access object property using variable
11 answers
I have an array in which I want to loop through each element and find it's value from the props which is passed to the component.
array = ['a','b','c']
I want to save the value of 'this.props.a' to a variable 'a; and similarly for other variables considering props does have the values saved , how can I do that ?
sample code :
buildURL() {
const param_array=array = ['a','b','c']
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props.param))
)
Here I need this.props.search_item , this.props.search_type , this.props.article_quality and this.props.min_views .
How can I get that?
javascript reactjs
This question already has an answer here:
Dynamically access object property using variable
11 answers
I have an array in which I want to loop through each element and find it's value from the props which is passed to the component.
array = ['a','b','c']
I want to save the value of 'this.props.a' to a variable 'a; and similarly for other variables considering props does have the values saved , how can I do that ?
sample code :
buildURL() {
const param_array=array = ['a','b','c']
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props.param))
)
Here I need this.props.search_item , this.props.search_type , this.props.article_quality and this.props.min_views .
How can I get that?
This question already has an answer here:
Dynamically access object property using variable
11 answers
javascript reactjs
javascript reactjs
edited Mar 8 at 1:25
Himanshu Jotwani
asked Mar 7 at 3:17
Himanshu JotwaniHimanshu Jotwani
17610
17610
marked as duplicate by Henry Woody, Community♦ Mar 8 at 1:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Henry Woody, Community♦ Mar 8 at 1:22
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Seems like you're looking for something like lodash'spick
? lodash.com/docs/4.17.11#pick
– Strebler
Mar 7 at 3:31
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50
add a comment |
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Seems like you're looking for something like lodash'spick
? lodash.com/docs/4.17.11#pick
– Strebler
Mar 7 at 3:31
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Seems like you're looking for something like lodash's
pick
? lodash.com/docs/4.17.11#pick– Strebler
Mar 7 at 3:31
Seems like you're looking for something like lodash's
pick
? lodash.com/docs/4.17.11#pick– Strebler
Mar 7 at 3:31
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50
add a comment |
2 Answers
2
active
oldest
votes
Currently your code looks for this.props.param
on each iteration of the map. Note that this does not mean it looks for the key in props
equal to the value of param
the variable, but looks for the key in props
called "param"
(equivalent to this.props["param"]
).
To use a variable as a key in an object you need to use the brackets notation: this.props[param]
In your code:
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
paramValue = this.props[param];
param_values.push(encodeURIComponent(paramValue))
)
Edit
To store a record of each key, value pair for those keys in param_array
and values from this.props
, you can create a new object in this way:
buildURL()
const paramArray=['search_term','search_type','article_quality','min_views'];
const paramObject = ;
for (const param of paramArray)
paramObject[param] = this.props[param];
// ...
Basically, create a new, empty object (paramObject
), then loop over each param
in paramArray
and assign the value for that param in the new object equal to the value for that param in this.props
. The final object will have a key for each param in paramArray
and values coming from this.props
.
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the.map
scope?
– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)search_term
, you can just define it likesearch_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in theprops
object for you. Do you want an object that contains only the keys specified inparam_array
? What's the use case?
– Henry Woody
Mar 7 at 4:07
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
|
show 1 more comment
You can try object[property]
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props[param]))
)
UPDATE:
If you want to store these into a variable, you can do it with reduce
.
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
let queryStringUrl = window.location.href.split('?')[0];
const param_values = param_array.reduce((acc, param)=>
acc[param]= encodeURIComponent(this.props[param])
return acc;
, )
return param_values
Now your param_values
is an object with the format
//param_values
search_term: /*encoded str*/,
search_type: /*encoded str*/,
...
And you can access it easily.
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.reduce
looping too, and you don't have to type it manually. Did you read the code I updated?
– bird
Mar 7 at 4:22
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Currently your code looks for this.props.param
on each iteration of the map. Note that this does not mean it looks for the key in props
equal to the value of param
the variable, but looks for the key in props
called "param"
(equivalent to this.props["param"]
).
To use a variable as a key in an object you need to use the brackets notation: this.props[param]
In your code:
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
paramValue = this.props[param];
param_values.push(encodeURIComponent(paramValue))
)
Edit
To store a record of each key, value pair for those keys in param_array
and values from this.props
, you can create a new object in this way:
buildURL()
const paramArray=['search_term','search_type','article_quality','min_views'];
const paramObject = ;
for (const param of paramArray)
paramObject[param] = this.props[param];
// ...
Basically, create a new, empty object (paramObject
), then loop over each param
in paramArray
and assign the value for that param in the new object equal to the value for that param in this.props
. The final object will have a key for each param in paramArray
and values coming from this.props
.
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the.map
scope?
– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)search_term
, you can just define it likesearch_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in theprops
object for you. Do you want an object that contains only the keys specified inparam_array
? What's the use case?
– Henry Woody
Mar 7 at 4:07
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
|
show 1 more comment
Currently your code looks for this.props.param
on each iteration of the map. Note that this does not mean it looks for the key in props
equal to the value of param
the variable, but looks for the key in props
called "param"
(equivalent to this.props["param"]
).
To use a variable as a key in an object you need to use the brackets notation: this.props[param]
In your code:
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
paramValue = this.props[param];
param_values.push(encodeURIComponent(paramValue))
)
Edit
To store a record of each key, value pair for those keys in param_array
and values from this.props
, you can create a new object in this way:
buildURL()
const paramArray=['search_term','search_type','article_quality','min_views'];
const paramObject = ;
for (const param of paramArray)
paramObject[param] = this.props[param];
// ...
Basically, create a new, empty object (paramObject
), then loop over each param
in paramArray
and assign the value for that param in the new object equal to the value for that param in this.props
. The final object will have a key for each param in paramArray
and values coming from this.props
.
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the.map
scope?
– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)search_term
, you can just define it likesearch_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in theprops
object for you. Do you want an object that contains only the keys specified inparam_array
? What's the use case?
– Henry Woody
Mar 7 at 4:07
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
|
show 1 more comment
Currently your code looks for this.props.param
on each iteration of the map. Note that this does not mean it looks for the key in props
equal to the value of param
the variable, but looks for the key in props
called "param"
(equivalent to this.props["param"]
).
To use a variable as a key in an object you need to use the brackets notation: this.props[param]
In your code:
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
paramValue = this.props[param];
param_values.push(encodeURIComponent(paramValue))
)
Edit
To store a record of each key, value pair for those keys in param_array
and values from this.props
, you can create a new object in this way:
buildURL()
const paramArray=['search_term','search_type','article_quality','min_views'];
const paramObject = ;
for (const param of paramArray)
paramObject[param] = this.props[param];
// ...
Basically, create a new, empty object (paramObject
), then loop over each param
in paramArray
and assign the value for that param in the new object equal to the value for that param in this.props
. The final object will have a key for each param in paramArray
and values coming from this.props
.
Currently your code looks for this.props.param
on each iteration of the map. Note that this does not mean it looks for the key in props
equal to the value of param
the variable, but looks for the key in props
called "param"
(equivalent to this.props["param"]
).
To use a variable as a key in an object you need to use the brackets notation: this.props[param]
In your code:
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
const param_values=[];
let queryStringUrl = window.location.href.split('?')[0];
param_array.map((param)=>
paramValue = this.props[param];
param_values.push(encodeURIComponent(paramValue))
)
Edit
To store a record of each key, value pair for those keys in param_array
and values from this.props
, you can create a new object in this way:
buildURL()
const paramArray=['search_term','search_type','article_quality','min_views'];
const paramObject = ;
for (const param of paramArray)
paramObject[param] = this.props[param];
// ...
Basically, create a new, empty object (paramObject
), then loop over each param
in paramArray
and assign the value for that param in the new object equal to the value for that param in this.props
. The final object will have a key for each param in paramArray
and values coming from this.props
.
edited Mar 7 at 4:50
answered Mar 7 at 3:37
Henry WoodyHenry Woody
4,81531127
4,81531127
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the.map
scope?
– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)search_term
, you can just define it likesearch_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in theprops
object for you. Do you want an object that contains only the keys specified inparam_array
? What's the use case?
– Henry Woody
Mar 7 at 4:07
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
|
show 1 more comment
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the.map
scope?
– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)search_term
, you can just define it likesearch_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in theprops
object for you. Do you want an object that contains only the keys specified inparam_array
? What's the use case?
– Henry Woody
Mar 7 at 4:07
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
Could you please tell me how can I store it in a variable for that block scope? Somewhat like search_term =this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:49
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the
.map
scope?– Henry Woody
Mar 7 at 3:53
@HimanshuJotwani I'm not sure what you mean exactly. Do you mean store the value of the prop within the
.map
scope?– Henry Woody
Mar 7 at 3:53
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
Not exactly , I want to store a variable named search_term in the scope of build_url
– Himanshu Jotwani
Mar 7 at 4:06
@HimanshuJotwani if you want a variable called (exactly)
search_term
, you can just define it like search_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in the props
object for you. Do you want an object that contains only the keys specified in param_array
? What's the use case?– Henry Woody
Mar 7 at 4:07
@HimanshuJotwani if you want a variable called (exactly)
search_term
, you can just define it like search_term = this.props.search_term;
. If you mean something more general, you can store values in an array or object, but the values here are already stored in the props
object for you. Do you want an object that contains only the keys specified in param_array
? What's the use case?– Henry Woody
Mar 7 at 4:07
1
1
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
@HimanshuJotwani I made an edit to the post, does that help?
– Henry Woody
Mar 7 at 4:23
|
show 1 more comment
You can try object[property]
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props[param]))
)
UPDATE:
If you want to store these into a variable, you can do it with reduce
.
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
let queryStringUrl = window.location.href.split('?')[0];
const param_values = param_array.reduce((acc, param)=>
acc[param]= encodeURIComponent(this.props[param])
return acc;
, )
return param_values
Now your param_values
is an object with the format
//param_values
search_term: /*encoded str*/,
search_type: /*encoded str*/,
...
And you can access it easily.
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.reduce
looping too, and you don't have to type it manually. Did you read the code I updated?
– bird
Mar 7 at 4:22
add a comment |
You can try object[property]
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props[param]))
)
UPDATE:
If you want to store these into a variable, you can do it with reduce
.
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
let queryStringUrl = window.location.href.split('?')[0];
const param_values = param_array.reduce((acc, param)=>
acc[param]= encodeURIComponent(this.props[param])
return acc;
, )
return param_values
Now your param_values
is an object with the format
//param_values
search_term: /*encoded str*/,
search_type: /*encoded str*/,
...
And you can access it easily.
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.reduce
looping too, and you don't have to type it manually. Did you read the code I updated?
– bird
Mar 7 at 4:22
add a comment |
You can try object[property]
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props[param]))
)
UPDATE:
If you want to store these into a variable, you can do it with reduce
.
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
let queryStringUrl = window.location.href.split('?')[0];
const param_values = param_array.reduce((acc, param)=>
acc[param]= encodeURIComponent(this.props[param])
return acc;
, )
return param_values
Now your param_values
is an object with the format
//param_values
search_term: /*encoded str*/,
search_type: /*encoded str*/,
...
And you can access it easily.
You can try object[property]
param_array.map((param)=>
param_values.push(encodeURIComponent(this.props[param]))
)
UPDATE:
If you want to store these into a variable, you can do it with reduce
.
buildURL()
const param_array=['search_term','search_type','article_quality','min_views'];
let queryStringUrl = window.location.href.split('?')[0];
const param_values = param_array.reduce((acc, param)=>
acc[param]= encodeURIComponent(this.props[param])
return acc;
, )
return param_values
Now your param_values
is an object with the format
//param_values
search_term: /*encoded str*/,
search_type: /*encoded str*/,
...
And you can access it easily.
edited Mar 7 at 4:06
answered Mar 7 at 3:34
birdbird
857620
857620
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.reduce
looping too, and you don't have to type it manually. Did you read the code I updated?
– bird
Mar 7 at 4:22
add a comment |
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.reduce
looping too, and you don't have to type it manually. Did you read the code I updated?
– bird
Mar 7 at 4:22
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
Could you tell me how can I store it in a variable for that block scope , somewhat like let search_term = this.props.search_term
– Himanshu Jotwani
Mar 7 at 3:50
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
I updated my answer. Is that what you are looking for?
– bird
Mar 7 at 4:10
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
Yes , kind of that but by looping through the array so that I don't have to type manually that search_term : this.props.search_term
– Himanshu Jotwani
Mar 7 at 4:19
ya.
reduce
looping too, and you don't have to type it manually. Did you read the code I updated?– bird
Mar 7 at 4:22
ya.
reduce
looping too, and you don't have to type it manually. Did you read the code I updated?– bird
Mar 7 at 4:22
add a comment |
please show more of your code.
– Dhaval Jardosh
Mar 7 at 3:22
Need more description and code in order to understand, please update the question
– satwik
Mar 7 at 3:28
Seems like you're looking for something like lodash's
pick
? lodash.com/docs/4.17.11#pick– Strebler
Mar 7 at 3:31
Question updated. @Strebler , not exactly
– Himanshu Jotwani
Mar 7 at 3:33
@HimanshuJotwani, why do you want these values stored in variables in the function scope? what will you do with them then? I think if you show that then we'll be able to provide a much simpler solution.
– lecstor
Mar 7 at 4:50