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>
Related
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
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.
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 2 years ago.
Improve this question
This works
console.log(comments[i].includes("NEW ENTRY"));
This doesn't work
while ((comments[i].includes("NEW ENTRY")) == false) {
//Some code
}
With the little information you give us, I would say that you do not manage the incrementation of your variable i.
const arrStr = ["hello", "asdf", "dfa"]
arrStr[0].includes("hel") // -> true
arrStr[1].includes("hel") // -> false
arrStr[2].includes("hel") // -> false
arrStr[3].includes("hel") // -> cannot read property 'includes' of undefined
If you look at the DCR's answers you will see how to manage the incrementation
both work just fine! It's likely that your i counter is wrong.
var comments=['try a little harder','NEW ENTRY',"another test"];
console.log(comments[1].includes("NEW ENTRY"));
var i = 0;
while ((comments[i].includes("NEW ENTRY")) == false) {
console.log(comments[i]);
i++;}
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 3 years ago.
Improve this question
Is it possible to manage object's properties via set get in defineProperty?
I'm not sure that I'm using this sentence properly.
<div id="app"></div>
why
<script>
var div = document.querySelector('#app');
var viewModel = {};
Object.defineProperty(viewModel, 'str' , {
get: function() {
return console.log("access");
},
set: function() {
return console.log("setting");
}
})
</script>
I assume that you have run viewModel.go in console - you will get "access" printed in console, but later you will get undefined as it is a result of this get function:
function() {
console.log("access");
}
This function doesn't have a return clause, so value of go will be undefined.
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