0
I don’t know how to call this to Google search or if it is possible to do this. I have an object that is as follows:
var clear = {
Search_r: false,
Search_f: false,
Search_e: false
}
And I have the following function
function clearSearch(clear) {
if(clear.Search_r) {
$(".search-r").html("")
}
if(clear.Search_f) {
$(".search-f").html("")
}
if(clear.Search_e) {
$(".search-e").html("")
}
}
I call it that
clear.Search_r = true
clearSearch(clear)
It works very well, but I wanted to know how to pass the true
within the function call and not on the top line. Something like:
clearSearch(clear.Search_r = true) //isso não funciona e nem da erro
I mean, it doesn’t work, from Undefined. How would be correct and if possible, how to write this in Google to find other solutions?
What is your intention to do this (pass the value to variable within the call)? being that the first way is working.
– sant0will
"i have a variable of type array which is the following", your example is not an array, is an object, it would be an array if so, for example:
var clear = [ { ...}, {....} ];
– Ricardo Pontual
@sant0will use 1 line instead of two and learn how to do this for something more complex
– flourigh
@Ricardopunctual legal, thank you
– flourigh
clearSearch(clear.Search_r = true)
this syntax works in some languages, but unfortunately injavascript
no :( you have to pass the object with a boolean property inside (eg:var parm = { Search_r = true }; clearSearch(param)
, or in the simplest way:clearSearch(true)
– Ricardo Pontual
@Ricardopunctual is that I really wanted to use the fewest possible lines, in this example would still use 2
– flourigh