Loop object that in the array and in the another object
i have the following structure. I need to get Internal value and through in the React. I think i need to get an array of values, for example: ['Bitcoin', 'Etherium'...] and map through it. How can i implement it?
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
]
javascript arrays reactjs object
add a comment |
i have the following structure. I need to get Internal value and through in the React. I think i need to get an array of values, for example: ['Bitcoin', 'Etherium'...] and map through it. How can i implement it?
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
]
javascript arrays reactjs object
add a comment |
i have the following structure. I need to get Internal value and through in the React. I think i need to get an array of values, for example: ['Bitcoin', 'Etherium'...] and map through it. How can i implement it?
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
]
javascript arrays reactjs object
i have the following structure. I need to get Internal value and through in the React. I think i need to get an array of values, for example: ['Bitcoin', 'Etherium'...] and map through it. How can i implement it?
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
]
javascript arrays reactjs object
javascript arrays reactjs object
edited Dec 30 '18 at 17:27
Jack Bashford
7,09031337
7,09031337
asked Dec 30 '18 at 17:19
Sasha ZoriaSasha Zoria
757
757
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here's how you'd get an array of coin names using Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
@JackBashford - You need them when you need to lookup a key via a var.const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
changelet
andvar
toconst
and this answer is perfect
– Pavlo
Dec 30 '18 at 17:31
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
|
show 3 more comments
Do it like this
import React from 'react'
export default class YourComponent extends React.Component {
render() {
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
]
let newArr = arr.map((data) => {
return data.CoinInfo.FullName
})
console.log('new array', newArr);
return (
<div>
</div>
)
}
}
1
You’re getting downvotes because this is not how you usemap()
.map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.
– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
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%2f53979774%2floop-object-that-in-the-array-and-in-the-another-object%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
Here's how you'd get an array of coin names using Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
@JackBashford - You need them when you need to lookup a key via a var.const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
changelet
andvar
toconst
and this answer is perfect
– Pavlo
Dec 30 '18 at 17:31
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
|
show 3 more comments
Here's how you'd get an array of coin names using Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
@JackBashford - You need them when you need to lookup a key via a var.const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
changelet
andvar
toconst
and this answer is perfect
– Pavlo
Dec 30 '18 at 17:31
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
|
show 3 more comments
Here's how you'd get an array of coin names using Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
Here's how you'd get an array of coin names using Array.prototype.map()
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
const arr = [{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
];
const coinNames = arr.map(x => x.CoinInfo.FullName);
console.log(coinNames);
edited Dec 30 '18 at 18:54
answered Dec 30 '18 at 17:26
Jack BashfordJack Bashford
7,09031337
7,09031337
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
@JackBashford - You need them when you need to lookup a key via a var.const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
changelet
andvar
toconst
and this answer is perfect
– Pavlo
Dec 30 '18 at 17:31
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
|
show 3 more comments
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
@JackBashford - You need them when you need to lookup a key via a var.const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
changelet
andvar
toconst
and this answer is perfect
– Pavlo
Dec 30 '18 at 17:31
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
4
4
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
Just use dot notation, no point for brackets
– Ionut Achim
Dec 30 '18 at 17:28
2
2
@JackBashford - You need them when you need to lookup a key via a var.
const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
@JackBashford - You need them when you need to lookup a key via a var.
const propName = 'Name'; const value = obj[propName];
– Amir Popovich
Dec 30 '18 at 17:30
2
2
change
let
and var
to const
and this answer is perfect– Pavlo
Dec 30 '18 at 17:31
change
let
and var
to const
and this answer is perfect– Pavlo
Dec 30 '18 at 17:31
1
1
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
Ah, of course @AmirPopovich That makes sense - if you used dots in that example, it would create a property literally named propName. Thanks for clarifying that.
– Jack Bashford
Dec 30 '18 at 17:32
1
1
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
Object property names are always strings. You only wrap them in quotes when they are the same as reserved words or are not valid J's identifiers (e.g. contain a space, hyphen or starts with a number).
– Ionut Achim
Dec 30 '18 at 17:36
|
show 3 more comments
Do it like this
import React from 'react'
export default class YourComponent extends React.Component {
render() {
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
]
let newArr = arr.map((data) => {
return data.CoinInfo.FullName
})
console.log('new array', newArr);
return (
<div>
</div>
)
}
}
1
You’re getting downvotes because this is not how you usemap()
.map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.
– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
add a comment |
Do it like this
import React from 'react'
export default class YourComponent extends React.Component {
render() {
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
]
let newArr = arr.map((data) => {
return data.CoinInfo.FullName
})
console.log('new array', newArr);
return (
<div>
</div>
)
}
}
1
You’re getting downvotes because this is not how you usemap()
.map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.
– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
add a comment |
Do it like this
import React from 'react'
export default class YourComponent extends React.Component {
render() {
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
]
let newArr = arr.map((data) => {
return data.CoinInfo.FullName
})
console.log('new array', newArr);
return (
<div>
</div>
)
}
}
Do it like this
import React from 'react'
export default class YourComponent extends React.Component {
render() {
let arr = [
{
"CoinInfo": {
"Id": "1182",
"Name": "BTC",
"FullName": "Bitcoin",
"Internal": "BTC",
"ImageUrl": "/media/19633/btc.png",
"Url": "/coins/btc/overview"
}
},
{
"CoinInfo": {
"Id": "7605",
"Name": "ETH",
"FullName": "Ethereum",
"Internal": "ETH",
"ImageUrl": "/media/20646/eth_logo.png",
"Url": "/coins/eth/overview"
}
}
]
let newArr = arr.map((data) => {
return data.CoinInfo.FullName
})
console.log('new array', newArr);
return (
<div>
</div>
)
}
}
edited Dec 30 '18 at 17:41
answered Dec 30 '18 at 17:26
Vikas SinghVikas Singh
482514
482514
1
You’re getting downvotes because this is not how you usemap()
.map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.
– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
add a comment |
1
You’re getting downvotes because this is not how you usemap()
.map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.
– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
1
1
You’re getting downvotes because this is not how you use
map()
. map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.– Mark Meyer
Dec 30 '18 at 17:36
You’re getting downvotes because this is not how you use
map()
. map()
creates and returns an array. Using it to loop over and push into another array is redundant. See the answers above for examples.– Mark Meyer
Dec 30 '18 at 17:36
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer Thank you so much for the help! I did the mistake and later I have corrected it.
– Vikas Singh
Dec 30 '18 at 17:51
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
@MarkMeyer I could have done it but I thought this is the best lesson I got.
– Vikas Singh
Dec 30 '18 at 18:01
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%2f53979774%2floop-object-that-in-the-array-and-in-the-another-object%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