Cannot read property 'length' of undefined despite check for undefined
I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:
render() {
var metadata = this.props.data["metadata"]
if(typeof metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
The render method is inside a component, which is placed inside another, by doing
<Marksheet data={this.state.data} />
I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.
javascript reactjs
|
show 3 more comments
I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:
render() {
var metadata = this.props.data["metadata"]
if(typeof metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
The render method is inside a component, which is placed inside another, by doing
<Marksheet data={this.state.data} />
I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.
javascript reactjs
2
!== 'undefined'->!== undefined
– ic3b3rg
Dec 28 '18 at 0:03
1
You have a space inmetadata .length, just before the dot ... was that a copy-paste mistake?
– LGSon
Dec 28 '18 at 0:04
also, can be simplified toif (metadata && metadata.length) { ... }
– ic3b3rg
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
1
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08
|
show 3 more comments
I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:
render() {
var metadata = this.props.data["metadata"]
if(typeof metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
The render method is inside a component, which is placed inside another, by doing
<Marksheet data={this.state.data} />
I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.
javascript reactjs
I'm writing some code to generate JSX based on items in an array, however I'm getting the error 'Cannot read property 'length' of undefined' despite having checks in place to see whether the variable is actually undefined. The code is really long so I've summarised the problem here:
render() {
var metadata = this.props.data["metadata"]
if(typeof metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
The render method is inside a component, which is placed inside another, by doing
<Marksheet data={this.state.data} />
I've checked to make sure that data is actually defined and being supplied as a prop, but even if it was undefined, I don't understand why it's saying cannot read property length of undefined.
javascript reactjs
javascript reactjs
edited Dec 28 '18 at 0:17
asked Dec 28 '18 at 0:01
Ray A.
838
838
2
!== 'undefined'->!== undefined
– ic3b3rg
Dec 28 '18 at 0:03
1
You have a space inmetadata .length, just before the dot ... was that a copy-paste mistake?
– LGSon
Dec 28 '18 at 0:04
also, can be simplified toif (metadata && metadata.length) { ... }
– ic3b3rg
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
1
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08
|
show 3 more comments
2
!== 'undefined'->!== undefined
– ic3b3rg
Dec 28 '18 at 0:03
1
You have a space inmetadata .length, just before the dot ... was that a copy-paste mistake?
– LGSon
Dec 28 '18 at 0:04
also, can be simplified toif (metadata && metadata.length) { ... }
– ic3b3rg
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
1
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08
2
2
!== 'undefined' -> !== undefined– ic3b3rg
Dec 28 '18 at 0:03
!== 'undefined' -> !== undefined– ic3b3rg
Dec 28 '18 at 0:03
1
1
You have a space in
metadata .length, just before the dot ... was that a copy-paste mistake?– LGSon
Dec 28 '18 at 0:04
You have a space in
metadata .length, just before the dot ... was that a copy-paste mistake?– LGSon
Dec 28 '18 at 0:04
also, can be simplified to
if (metadata && metadata.length) { ... }– ic3b3rg
Dec 28 '18 at 0:05
also, can be simplified to
if (metadata && metadata.length) { ... }– ic3b3rg
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
1
1
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08
|
show 3 more comments
3 Answers
3
active
oldest
votes
You could also use the Array.isArray method:
render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
add a comment |
The string "undefined" is not the same as undefined.
Try changing your code to the following:
render() {
var metadata = this.props.data["metadata"]
if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing whatmetadatais equal to?
– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So thenmetadatais defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
|
show 5 more comments
Or just simply. You might also check for metadata.length >0 (instead of just length)
render() {
var metadata = this.props.data["metadata"]
if(metadata && metadata.length) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
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%2f53952201%2fcannot-read-property-length-of-undefined-despite-check-for-undefined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You could also use the Array.isArray method:
render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
add a comment |
You could also use the Array.isArray method:
render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
add a comment |
You could also use the Array.isArray method:
render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}
You could also use the Array.isArray method:
render() {
var metadata = this.props.data["metadata"];
if(Array.isArray(metadata)) {
metadata.forEach(val => console.log(val));
}
}
answered Dec 28 '18 at 0:32
quirimmo
6,03111129
6,03111129
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
add a comment |
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
1
1
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
This conditional check is simple and short. No need to bother about whether it is undefined or null. Array.isArray is enough to do conditional check so +1 upvote for you
– Hemadri Dasari
Dec 28 '18 at 3:26
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
I've just tried isArray. Strangely it's still coming up with the same error. I tried if(Array.isArray(metadata)) { console.log("it's an array!") console.log("the length is: " + metadata.length) which prints out the length correctly, but the javascript console still says unable to read property length of undefined, and the app crashes :(
– Ray A.
Dec 28 '18 at 7:33
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
That error cannot come from that code, you have somewhere else some error prone code. Maybe in componentDidMount?
– quirimmo
Dec 28 '18 at 7:43
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
You're right. Looks like another part of the code was giving the same error
– Ray A.
Dec 29 '18 at 21:24
add a comment |
The string "undefined" is not the same as undefined.
Try changing your code to the following:
render() {
var metadata = this.props.data["metadata"]
if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing whatmetadatais equal to?
– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So thenmetadatais defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
|
show 5 more comments
The string "undefined" is not the same as undefined.
Try changing your code to the following:
render() {
var metadata = this.props.data["metadata"]
if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing whatmetadatais equal to?
– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So thenmetadatais defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
|
show 5 more comments
The string "undefined" is not the same as undefined.
Try changing your code to the following:
render() {
var metadata = this.props.data["metadata"]
if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.
The string "undefined" is not the same as undefined.
Try changing your code to the following:
render() {
var metadata = this.props.data["metadata"]
if(metadata !== undefined && metadata.length !== undefined) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
That basically checks to ensure both metadata and metadata.length are not equal to undefined before running that for loop.
answered Dec 28 '18 at 0:04
Charlie Fish
5,43942971
5,43942971
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing whatmetadatais equal to?
– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So thenmetadatais defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
|
show 5 more comments
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing whatmetadatais equal to?
– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So thenmetadatais defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?
– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
Thank's for the quick reply! I've changed it to underfined instead of 'undefined' but I'm still getting the same error. Also checked with null
– Ray A.
Dec 28 '18 at 0:06
@RayA. Of course! Can you try printing what
metadata is equal to?– Charlie Fish
Dec 28 '18 at 0:07
@RayA. Of course! Can you try printing what
metadata is equal to?– Charlie Fish
Dec 28 '18 at 0:07
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
Doing console.log("Metadata: " + metadata) prints out "Metadata: Student name, task_id,..."
– Ray A.
Dec 28 '18 at 0:12
@RayA. So then
metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?– Charlie Fish
Dec 28 '18 at 0:13
@RayA. So then
metadata is defined looks like. Are you sure the error you posted is correct and is happening where you say it's happening?– Charlie Fish
Dec 28 '18 at 0:13
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
I've double checked the error. This is what comes up in the javascript console: Uncaught TypeError: Cannot read property 'length' of undefined at ProxyComponent.render ... The above error occurred in the <Marksheet> component: in Marksheet (at Interaction.jsx:579)
– Ray A.
Dec 28 '18 at 0:15
|
show 5 more comments
Or just simply. You might also check for metadata.length >0 (instead of just length)
render() {
var metadata = this.props.data["metadata"]
if(metadata && metadata.length) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
add a comment |
Or just simply. You might also check for metadata.length >0 (instead of just length)
render() {
var metadata = this.props.data["metadata"]
if(metadata && metadata.length) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
add a comment |
Or just simply. You might also check for metadata.length >0 (instead of just length)
render() {
var metadata = this.props.data["metadata"]
if(metadata && metadata.length) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
Or just simply. You might also check for metadata.length >0 (instead of just length)
render() {
var metadata = this.props.data["metadata"]
if(metadata && metadata.length) {
for(var i=0; i<metadata.length; i++) {
console.log(metadata[i]);
}
}
}
answered Dec 28 '18 at 9:23
Nicholas
1,29811320
1,29811320
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%2f53952201%2fcannot-read-property-length-of-undefined-despite-check-for-undefined%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
!== 'undefined'->!== undefined– ic3b3rg
Dec 28 '18 at 0:03
1
You have a space in
metadata .length, just before the dot ... was that a copy-paste mistake?– LGSon
Dec 28 '18 at 0:04
also, can be simplified to
if (metadata && metadata.length) { ... }– ic3b3rg
Dec 28 '18 at 0:05
@LGSon A space matter so long as it actually is a space. If it's a weird unicode character then that is a problem.
– Charlie Fish
Dec 28 '18 at 0:05
1
@LGSon Spaces before a dot, while possibly unintentional, won't have any effect on the code
– CertainPerformance
Dec 28 '18 at 0:08