How to loop array one column data
I have an array like this.
[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]
Now I need to get the Recommendedby
column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid
.
Please tell me how to achieve this.
javascript angular
add a comment |
I have an array like this.
[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]
Now I need to get the Recommendedby
column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid
.
Please tell me how to achieve this.
javascript angular
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53
add a comment |
I have an array like this.
[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]
Now I need to get the Recommendedby
column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid
.
Please tell me how to achieve this.
javascript angular
I have an array like this.
[
{"Test": "1", "Recommendedby": "3,4,5,6"},
{"ABC": "2", "Recommendedby": "1,2,3"},
{"Cvb": "3", "Recommendedby": ""}
]
Now I need to get the Recommendedby
column and I want to this column data means I need to send each number in recommended column data to service to get the username of that userid
.
Please tell me how to achieve this.
javascript angular
javascript angular
edited Nov 12 '18 at 14:52
Jacob van Lingen
4,63422951
4,63422951
asked Nov 12 '18 at 14:03
Prasanna
134
134
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53
add a comment |
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53
add a comment |
2 Answers
2
active
oldest
votes
To achieve expected use below option of looping through array with forEach
- Use forEach to loop through array
- Use split with comma to create another array for Recommendedby
- Use anoher forEach to loop through Recommendedby array
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
add a comment |
Try like this :
let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]
array.map(item => item.Recommendedby.split(',').map(id => {
// this.http.getUser(id).subscribe(...)
}))
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%2f53263794%2fhow-to-loop-array-one-column-data%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
To achieve expected use below option of looping through array with forEach
- Use forEach to loop through array
- Use split with comma to create another array for Recommendedby
- Use anoher forEach to loop through Recommendedby array
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
add a comment |
To achieve expected use below option of looping through array with forEach
- Use forEach to loop through array
- Use split with comma to create another array for Recommendedby
- Use anoher forEach to loop through Recommendedby array
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
add a comment |
To achieve expected use below option of looping through array with forEach
- Use forEach to loop through array
- Use split with comma to create another array for Recommendedby
- Use anoher forEach to loop through Recommendedby array
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010
To achieve expected use below option of looping through array with forEach
- Use forEach to loop through array
- Use split with comma to create another array for Recommendedby
- Use anoher forEach to loop through Recommendedby array
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
codepen - https://codepen.io/nagasai/pen/XyNgEG?editors=1010
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
let arr = [{"Test":1,"Recommendedby":"3,4,5,6"},{"ABC":"2","Recommendedby":"1,2,3"},{"Cvb":"3","Recommendedby":""}]
arr.forEach(v => v.Recommendedby.split(',').forEach(val => {
console.log("Recommended by id-", val); // make service call here to pass each id
}))
answered Nov 12 '18 at 14:56
Naga Sai A
5,5121825
5,5121825
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
add a comment |
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
Thank you..you saved my time.
– Prasanna
Nov 13 '18 at 8:45
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
np.. Glad it worked :)
– Naga Sai A
Nov 13 '18 at 14:38
add a comment |
Try like this :
let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]
array.map(item => item.Recommendedby.split(',').map(id => {
// this.http.getUser(id).subscribe(...)
}))
add a comment |
Try like this :
let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]
array.map(item => item.Recommendedby.split(',').map(id => {
// this.http.getUser(id).subscribe(...)
}))
add a comment |
Try like this :
let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]
array.map(item => item.Recommendedby.split(',').map(id => {
// this.http.getUser(id).subscribe(...)
}))
Try like this :
let array = [
{"Test":1,"Recommendedby":"3,4,5,6"},
{"ABC":"2","Recommendedby":"1,2,3"},
{"Cvb":"3","Recommendedby":""}
]
array.map(item => item.Recommendedby.split(',').map(id => {
// this.http.getUser(id).subscribe(...)
}))
edited Nov 12 '18 at 15:10
Suraj Rao
22.6k75469
22.6k75469
answered Nov 12 '18 at 14:59
Abderrahim Soubai Elidrissi
1,41011020
1,41011020
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53263794%2fhow-to-loop-array-one-column-data%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
your js object is not valid
– Suraj Rao
Nov 12 '18 at 14:49
can you provide expected array
– Naga Sai A
Nov 12 '18 at 14:51
This might be what you're after: stackoverflow.com/questions/18804592/…
– DonCarlosII
Nov 12 '18 at 14:53