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.
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 3 months ago.
Improve this question
i want to replace all the "_" occurrences from an array like this (TASK_1,TASK_2,TASK_3).
I receive this from the back-end and i cannot use the replace all because the project doesn't support es2021. I need to display the array like this (TASK 1,TASK 2, TASK 3).
I tried this method:
formatWithoutUnderScore(valueToFormat:any) {
return valueToFormat.map((value:any) => value.replace(/_/g, ' '));
}
and the used it:
this.formatWithoutUnderScore(this.totalTasks);
But it does nothing :(
Can someone help?
this.totalTasks = this.formatWithoutUnderScore(this.totalTasks);
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 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>"
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 3 years ago.
Improve this question
when i work in javascript canvas, when i created a basic object for aqngles like thius
const Angle =
{
Beginning:0*Math.PI,
OneQuarter:0.5*Math.PI,
TwoQuarter:1.0*Math.PI,
End:2*Math.Pi
}
and when i console log the outputs i get this:
0
NaN
but at the same time when i create unique consts for each like so:
const
startAngle = 0*Math.PI,
endAngle = 2*Math.PI;
and i console log it i get the response i want:
0
6.283185307179586
why does this happen? and how can i create a simple object with calculation and get a correct response? Thanks
Repl page:
https://repl.it/#Ballatoilet/EMDR
You have typo, it should be End:2*Math.PI and you have End:2*Math.Pi (small "i" letter).
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
Below is my code, for some reason it outputs undefined for ['6'] & ['7'], all the other ones work. I don't understand what is going wrong.
var array = [
['1'],
['2'],
['3'],
['4'],
['5'],
['6']
['7'],
['8'],
['9'],
['10']
];
if(document.getElementById("random-element")) {
var rand = array[Math.floor(Math.random() * array.length)];
document.getElementById('random-element').innerHTML = rand;
}
https://jsfiddle.net/ggky7a03/
You missed a comma in your array, which will explain why those 2 values are not returning (they don't exist)
Side note, array is a reserved word in JS, so you can't (shouldn't) use it for your variable name, so change it to
var myAwesomeArray = [
// or similar
Here's your fixed code