Call child object with space within parent object of no name
up vote
-1
down vote
favorite
Lets say I have the following...
Example code:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
How would I console log the 'key2 with space'
value's object as shown in the code above.
I tried the following console.log(array[0].['key with space'])
. But this results in a syntax error that isn't very will defined.
javascript
|
show 2 more comments
up vote
-1
down vote
favorite
Lets say I have the following...
Example code:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
How would I console log the 'key2 with space'
value's object as shown in the code above.
I tried the following console.log(array[0].['key with space'])
. But this results in a syntax error that isn't very will defined.
javascript
2
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
1
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38
|
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Lets say I have the following...
Example code:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
How would I console log the 'key2 with space'
value's object as shown in the code above.
I tried the following console.log(array[0].['key with space'])
. But this results in a syntax error that isn't very will defined.
javascript
Lets say I have the following...
Example code:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
How would I console log the 'key2 with space'
value's object as shown in the code above.
I tried the following console.log(array[0].['key with space'])
. But this results in a syntax error that isn't very will defined.
javascript
javascript
edited Nov 20 at 5:37
asked Nov 20 at 5:35
Fiddle Freak
7021532
7021532
2
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
1
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38
|
show 2 more comments
2
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
1
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38
2
2
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
1
1
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38
|
show 2 more comments
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
You can access object properties in two ways, one is using the dot (.
) operator and the other is using the square bracket (). You are using both. Since the key contains space, you have to use the bracket notation. Also, the key name you are trying in console does not match (
'key2 with space' != 'key with space'
).
Remove dot:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
You can access object properties in two ways, one is using the dot (.
) operator and the other is using the square bracket (). You are using both. Since the key contains space, you have to use the bracket notation. Also, the key name you are trying in console does not match (
'key2 with space' != 'key with space'
).
Remove dot:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
add a comment |
up vote
2
down vote
accepted
You can access object properties in two ways, one is using the dot (.
) operator and the other is using the square bracket (). You are using both. Since the key contains space, you have to use the bracket notation. Also, the key name you are trying in console does not match (
'key2 with space' != 'key with space'
).
Remove dot:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
You can access object properties in two ways, one is using the dot (.
) operator and the other is using the square bracket (). You are using both. Since the key contains space, you have to use the bracket notation. Also, the key name you are trying in console does not match (
'key2 with space' != 'key with space'
).
Remove dot:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
You can access object properties in two ways, one is using the dot (.
) operator and the other is using the square bracket (). You are using both. Since the key contains space, you have to use the bracket notation. Also, the key name you are trying in console does not match (
'key2 with space' != 'key with space'
).
Remove dot:
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
const array = [{
key1: {
keyA: 'hello world',
keyB: 'hello world'
},
'key2 with space': {
keyA: 'hello world',
keyB: 'hello world'
},
key3: {
keyA: 'hello world',
keyB: 'hello world'
}
}]
console.log(array[0]['key2 with space'])
edited Nov 20 at 5:46
answered Nov 20 at 5:38
Mamun
23.9k71428
23.9k71428
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
add a comment |
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
Great thanks ^^
– Fiddle Freak
Nov 20 at 5:39
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
@FiddleFreak, you are most welcome:)
– Mamun
Nov 20 at 5:40
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%2f53386829%2fcall-child-object-with-space-within-parent-object-of-no-name%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
2
You can remove dot (.) and try array[0]['key with space']
– Nitish Narang
Nov 20 at 5:36
Perfect thanks :D
– Fiddle Freak
Nov 20 at 5:37
@user202729 I did, sorry I will edit it
– Fiddle Freak
Nov 20 at 5:37
1
Possible duplicate of access javascript object with space in key
– Jeto
Nov 20 at 5:37
@Jeto I don't think it's a duplication of that question, because the question is a nested object not inside an array. And the parent array has a name.
– Fiddle Freak
Nov 20 at 5:38