can not convert this string to object [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 months ago.
Improve this question
I can not convert this string to object.Why I am getting this error? please help.
onSignup(data:any){
localStorage.setItem('users',JSON.stringify(data));
let users = JSON.parse(localStorage.getItem('users'));
}

Try using function onSignup(data: any) { localStorage.setItem('users', JSON.stringify(data)); let users = JSON.parse(localStorage.getItem('users') as string); }
If you are using typescript you can't pass a string | undefined when a string is expected.

Related

what is the work of .id in this given function [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 hours ago.
Improve this question
what is .id in this given function
function getSelected() {
let answer = undefined;
answerEls.forEach((answerEl) => {
if (answerEl.checked) {
answer = answerEl.id;
}
});
return answer;
}
I tried to find what is .id by console .log but it does does not show any value

How to format the number? I was looking for the answer but haven't been able find the right one [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 months ago.
Improve this question
So I have following numbers and I would like to format it in the following way
450.03,999,999 -> 450.03
2,597.6,099,999 -> 2,597.60
69.2 -> 69.20
100,780.090,100 -> 100,780.09
Could you assist with this issue? Thank you in advance.
you can get it done this way. I hope it would work for you.
let value = "2,597.6,099,999";
let num = Number(value.replace(/,/g, ""));
let result = num.toLocaleString(undefined, {minimumFractionDigits: 2})

Getting undefined values from JavaScript array [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I am getting response something like this in the form JavaScript Object
{
"result": [
{
"invoice_prefix": "INV",
"maximum_invoice_no": "0009"
}
]
}
I am trying to fetch the value of invoice_prefix and maximum_invoice_no
I have written result[0].maximum_invoice_no but I am getting undefined .
I have tried a lot of other ways also but still getting undefined . Please help me and give me some hint
I tried that and it is working as expected. I hope this will be helpful.
let test = {
"result": [
{
"invoice_prefix": "INV",
"maximum_invoice_no": "0009"
}
]
}
document.getElementById("output").innerHTML = "Maximum Invoice No. : " + test.result[0].maximum_invoice_no;
console.log(test.result[0].maximum_invoice_no);
<p id="output"></p>

Java Script function does not work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
var Structure[undefined]
function run{
Structure[0]
}
function setStructure(structure){
Structure[0]=structure
}
setStructure(House);
function House(){
//nothing
}
Why is the return of House() function not in Structure[0]?
It is for a Minecraft PE mod.
I suppose you intended this:
function run{
Structure[0]() // <--- notice the parentheses.
}
Without the parentheses, the function run does not do anything. It just references the function, without invoking it.

How to add data to the child node of a json [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to add data {"address" : "http://ebay.com"} to the second child of this json data i.e in the bracket with the data "api" : "Ebay".
How can I do that with jQuery?
{"Amazon":[
{"price":"19,799.00","delivery":"FREE","api":"Amazon"},
{"price":"29,999","delivery":"FREE","api":"Ebay"}
]
}
Try,
var obj = {"Amazon":[ {"price":"19,799.00","delivery":"FREE","api":"Amazon"},{"price":"29,999","delivery":"FREE","api":"Ebay"} ] };
obj.Amazon[1].address = "http://ebay.com";
or use $.merge(obj1,obj2) function
var obj = {"Amazon":[ {"price":"19,799.00","delivery":"FREE","api":"Amazon"},{"price":"29,999","delivery":"FREE","api":"Ebay"} ] };
$.merge(obj.Amazon[1], {
address: "http://ebay.com"
});
DEMO

Categories

Resources