Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I wanted to compare the value of variable which is getting the URL of current page with the hard coded string. Though the values are same I am getting false in the comparison. Not able to guess what is happening. Below is the code:
var loc = String('"' + window.URL + '"');
if("Here I am specifying entire URL manually exactly same which I am getting in loc"==String(loc))
{ console.log("true") }
else { console.log("false") }
This is pretty simple but I am missing something. Help needed. Thanks in advance.
You should use window.location.href instead . Since loc variable returns "function URL() { [native code] }" Hence the result is false.
window.location.href === "<Your string>"
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
how to concatenate a string with a variable's value in javascript (more specifically react).In this ToolsCard component, I am getting the title as prop and I want to make a string 'download title which is being received as prop, how should I do this.I tried the below way but I am getting an error, Is there some alternative to do this?
const ToolsCard = ({title}) => {
const str='download'+{title}
}
const ToolsCard = title => 'download ' + title;
I don't know what else to tell you. You might want to export the ToolsCard function maybe. And you should definitely read some Javascript and React tutorials.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have a JS function which checks if a user entered string is zero.
if (str.legth = 0) {
alert('Provide at least 1 character to create a folder.');
return;
}
But this seems to let a user pass a zero entered string.
Is there anything missing?
THanks
You've misspelled "length" and you need "==" instead of "=" to check for equailty rather than assigning a value.
If your variable is called str, then length is used to return a boolean value. You need to use either == or === for an actual comparison instead of an assignment. Additionally, a return isn't necessary.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
Hi im pretty sure what im about to post might not be enough info (if so please let me know what more is needed). I am using node js and having a really weird error. Below is the code and output.
if (currentPrice > variableData[i].stopLossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Output:
if
92.7
is more than
93.62700000000001
This is consistently happening. I also made sure that both currentPrice and variableData[i].stopLossHard are numbers and not strings (I made sure in the code and in the output its the color of a number not a string)
Any ideas is highly appreciated.
The attribute you print is different than the one you check in the if statement:
(In the if stopLossHard has a capital L, stop-L-ossHard, what you print doesn't)
Try this:
if (currentPrice > variableData[i].stoplossHard) {
console.log('if')
console.log(currentPrice)
console.log('is more than')
console.log(variableData[i].stoplossHard)
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm creating a site and i needed to do some js. I'm not that good with it but tought i would figer it out. Not. I created a for loop but it does not run.
function order(user,product){
var index;
for(var i = 0; i<users.lenght; i++){
if(user == users[i]){
index = i;
break;
}
}
var budget = budgets[index];
alert(budget);
}
the creation of the users and budgets arrays are done with php and after checking with alert() it was how it should be.
Can anyone help me please?
lenght is spelt length. The misspelt property does not exist, so it undefined, which is equivalent to 0.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have an javascript array of objects as follows :
list = [
{
"employee_work_rights_id":74,
"amazon_id":173,
"employee_id":3,
"work_rights":"australian_citizen",
"document_type":"password",
"display_name":"a.pdf",
"filename":"abc.pdf",
"s3bucket":"xyz",
"filepath":"employer27\/employee3\/"
},
{
"employee_work_rights_id":75,
"amazon_id":175,
"employee_id":3,
"work_rights":"australian_citizen",
"document_type":"password",
"display_name":"a.pdf",
"filename":"xyz.pdf",
"s3bucket":"zyx",
"filepath":"employer27\/employee3\/"
}
]
I tried to access amazon_id as follows :
console.log(list[0].amazon_id);
This is giving me undefined. How can I access this ?
You're doing the right thing. The way you initialize list is correct, and so is the way you access the property.
Assuming you were trying interactively in the console, the undefined you see is not the value of list[0].amazon_id. It's the return value of console.log. In Javascript, everything has a return value. However, in the console, just above or just below your undefined, you should see amazon_id's proper value.