nested forEach loops - error “forEach is not a function”
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I had a simple for each, but realised I needed to get a different property of my JSON, so I need now to have 2 nested forEach
loops, but I am not sure how to do this properly. I am getting an error saying my second forEach
is not a function.
I had this code first:
getExample.then(function(response) {
response.data.forEach(function(x) {
x.friendlyName = x.AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
than I tried to change it to this:
response.data.forEach(function (x) {
x.accounttransferfinalitycategory.forEach(function (y) {
x.friendlyName = x.accounttransferfinalitycategory[y].AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
But I get an error now, what is the proper way to do this?
javascript loops foreach
add a comment |
I had a simple for each, but realised I needed to get a different property of my JSON, so I need now to have 2 nested forEach
loops, but I am not sure how to do this properly. I am getting an error saying my second forEach
is not a function.
I had this code first:
getExample.then(function(response) {
response.data.forEach(function(x) {
x.friendlyName = x.AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
than I tried to change it to this:
response.data.forEach(function (x) {
x.accounttransferfinalitycategory.forEach(function (y) {
x.friendlyName = x.accounttransferfinalitycategory[y].AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
But I get an error now, what is the proper way to do this?
javascript loops foreach
1
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
2
please provide sample response data
– shajji
Jan 3 at 11:25
1
Is itx.AccountTransferFinalityCategoryName
orx.accounttransferfinalitycategoryname
? That really matters ...
– Jonas Wilms
Jan 3 at 11:26
we definitely need to see what the data is - but most likelyx.accounttransferfinalitycategory
isundefined
, either because the response isn't what you expect, or you mis-spelled the property name
– Robin Zigmond
Jan 3 at 11:27
add a comment |
I had a simple for each, but realised I needed to get a different property of my JSON, so I need now to have 2 nested forEach
loops, but I am not sure how to do this properly. I am getting an error saying my second forEach
is not a function.
I had this code first:
getExample.then(function(response) {
response.data.forEach(function(x) {
x.friendlyName = x.AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
than I tried to change it to this:
response.data.forEach(function (x) {
x.accounttransferfinalitycategory.forEach(function (y) {
x.friendlyName = x.accounttransferfinalitycategory[y].AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
But I get an error now, what is the proper way to do this?
javascript loops foreach
I had a simple for each, but realised I needed to get a different property of my JSON, so I need now to have 2 nested forEach
loops, but I am not sure how to do this properly. I am getting an error saying my second forEach
is not a function.
I had this code first:
getExample.then(function(response) {
response.data.forEach(function(x) {
x.friendlyName = x.AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
than I tried to change it to this:
response.data.forEach(function (x) {
x.accounttransferfinalitycategory.forEach(function (y) {
x.friendlyName = x.accounttransferfinalitycategory[y].AccountTransferFinalityCategoryName + "-" + x.AccountTransferFinalityName;
});
});
But I get an error now, what is the proper way to do this?
javascript loops foreach
javascript loops foreach
edited Jan 3 at 11:31
dns_nx
1,56311736
1,56311736
asked Jan 3 at 11:21
Ana SequeiraAna Sequeira
129211
129211
1
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
2
please provide sample response data
– shajji
Jan 3 at 11:25
1
Is itx.AccountTransferFinalityCategoryName
orx.accounttransferfinalitycategoryname
? That really matters ...
– Jonas Wilms
Jan 3 at 11:26
we definitely need to see what the data is - but most likelyx.accounttransferfinalitycategory
isundefined
, either because the response isn't what you expect, or you mis-spelled the property name
– Robin Zigmond
Jan 3 at 11:27
add a comment |
1
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
2
please provide sample response data
– shajji
Jan 3 at 11:25
1
Is itx.AccountTransferFinalityCategoryName
orx.accounttransferfinalitycategoryname
? That really matters ...
– Jonas Wilms
Jan 3 at 11:26
we definitely need to see what the data is - but most likelyx.accounttransferfinalitycategory
isundefined
, either because the response isn't what you expect, or you mis-spelled the property name
– Robin Zigmond
Jan 3 at 11:27
1
1
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
2
2
please provide sample response data
– shajji
Jan 3 at 11:25
please provide sample response data
– shajji
Jan 3 at 11:25
1
1
Is it
x.AccountTransferFinalityCategoryName
or x.accounttransferfinalitycategoryname
? That really matters ...– Jonas Wilms
Jan 3 at 11:26
Is it
x.AccountTransferFinalityCategoryName
or x.accounttransferfinalitycategoryname
? That really matters ...– Jonas Wilms
Jan 3 at 11:26
we definitely need to see what the data is - but most likely
x.accounttransferfinalitycategory
is undefined
, either because the response isn't what you expect, or you mis-spelled the property name– Robin Zigmond
Jan 3 at 11:27
we definitely need to see what the data is - but most likely
x.accounttransferfinalitycategory
is undefined
, either because the response isn't what you expect, or you mis-spelled the property name– Robin Zigmond
Jan 3 at 11:27
add a comment |
2 Answers
2
active
oldest
votes
I'm not sure what exactly you want to say , but i think your problem is with applying forEach
to object,
be sure that x.accounttransferfinalitycategory
is array , if it is object try below code
x = x.accounttransferfinalitycategory;
Object.keys(x).forEach(function (key){
console.log(x[key]);
});
or update your question with response and expected output :-)
add a comment |
I think you need this
$.each(result, function () { console.log(this.Id); console.log(this.Value); });
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021328%2fnested-foreach-loops-error-foreach-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm not sure what exactly you want to say , but i think your problem is with applying forEach
to object,
be sure that x.accounttransferfinalitycategory
is array , if it is object try below code
x = x.accounttransferfinalitycategory;
Object.keys(x).forEach(function (key){
console.log(x[key]);
});
or update your question with response and expected output :-)
add a comment |
I'm not sure what exactly you want to say , but i think your problem is with applying forEach
to object,
be sure that x.accounttransferfinalitycategory
is array , if it is object try below code
x = x.accounttransferfinalitycategory;
Object.keys(x).forEach(function (key){
console.log(x[key]);
});
or update your question with response and expected output :-)
add a comment |
I'm not sure what exactly you want to say , but i think your problem is with applying forEach
to object,
be sure that x.accounttransferfinalitycategory
is array , if it is object try below code
x = x.accounttransferfinalitycategory;
Object.keys(x).forEach(function (key){
console.log(x[key]);
});
or update your question with response and expected output :-)
I'm not sure what exactly you want to say , but i think your problem is with applying forEach
to object,
be sure that x.accounttransferfinalitycategory
is array , if it is object try below code
x = x.accounttransferfinalitycategory;
Object.keys(x).forEach(function (key){
console.log(x[key]);
});
or update your question with response and expected output :-)
edited Feb 2 at 3:23
Şivā SankĂr
1,29811022
1,29811022
answered Jan 3 at 11:52
HrishiHrishi
4121215
4121215
add a comment |
add a comment |
I think you need this
$.each(result, function () { console.log(this.Id); console.log(this.Value); });
add a comment |
I think you need this
$.each(result, function () { console.log(this.Id); console.log(this.Value); });
add a comment |
I think you need this
$.each(result, function () { console.log(this.Id); console.log(this.Value); });
I think you need this
$.each(result, function () { console.log(this.Id); console.log(this.Value); });
answered Jan 3 at 11:27
nrajsharma794nrajsharma794
92
92
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54021328%2fnested-foreach-loops-error-foreach-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Probably x.accounttransferfinalitycategory is not an array!!!
– Mamun
Jan 3 at 11:23
2
please provide sample response data
– shajji
Jan 3 at 11:25
1
Is it
x.AccountTransferFinalityCategoryName
orx.accounttransferfinalitycategoryname
? That really matters ...– Jonas Wilms
Jan 3 at 11:26
we definitely need to see what the data is - but most likely
x.accounttransferfinalitycategory
isundefined
, either because the response isn't what you expect, or you mis-spelled the property name– Robin Zigmond
Jan 3 at 11:27