JavaScript - Cannot read property 'toLowerCase' of undefined
Can't find the problem, but it keeps showing this error!! same happens when using other methods like includes.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)javascript arrays
add a comment |
Can't find the problem, but it keeps showing this error!! same happens when using other methods like includes.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)javascript arrays
3
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53
add a comment |
Can't find the problem, but it keeps showing this error!! same happens when using other methods like includes.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)javascript arrays
Can't find the problem, but it keeps showing this error!! same happens when using other methods like includes.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = note.body.toLowerCase().includes('ne')
return findFileredTitle )
console.log(filteredNotes)javascript arrays
javascript arrays
edited Nov 11 at 16:38
Eugene Mihaylin
9601424
9601424
asked Nov 11 at 15:51
Arif Hossain
84
84
3
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53
add a comment |
3
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53
3
3
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53
add a comment |
5 Answers
5
active
oldest
votes
Your array notes contains four elements. The first one empty. See the empty pair of braces?
let notes = [, {
When you later access it:
note.title.toLowerCase() === ...
Then note.title is undefined and you get the error message.
Most likely, you want to remote the empty pair of braces.
add a comment |
There is an object with no property title, because of that you're getting that error. It's something like:
undefined.toLowercase()
^
You can add a checking part on note.title as follow:
note.title && (note.title.toLowercase() === .........)
^
add a comment |
You need to provide null check before converting tilte and body to lowercase.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)add a comment |
Update your filter method to check if key exists then going for match other return false.
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title && note.title.toLowerCase().includes('ne')
let findFileredBody = note.body && note.body.toLowerCase().includes('ne')
return findFileredTitle );
add a comment |
Remove An empty '' object from array , note.title is null/Empty so it return error
let notes = [
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
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%2f53250442%2fjavascript-cannot-read-property-tolowercase-of-undefined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your array notes contains four elements. The first one empty. See the empty pair of braces?
let notes = [, {
When you later access it:
note.title.toLowerCase() === ...
Then note.title is undefined and you get the error message.
Most likely, you want to remote the empty pair of braces.
add a comment |
Your array notes contains four elements. The first one empty. See the empty pair of braces?
let notes = [, {
When you later access it:
note.title.toLowerCase() === ...
Then note.title is undefined and you get the error message.
Most likely, you want to remote the empty pair of braces.
add a comment |
Your array notes contains four elements. The first one empty. See the empty pair of braces?
let notes = [, {
When you later access it:
note.title.toLowerCase() === ...
Then note.title is undefined and you get the error message.
Most likely, you want to remote the empty pair of braces.
Your array notes contains four elements. The first one empty. See the empty pair of braces?
let notes = [, {
When you later access it:
note.title.toLowerCase() === ...
Then note.title is undefined and you get the error message.
Most likely, you want to remote the empty pair of braces.
answered Nov 11 at 15:58
Codo
50.4k11110148
50.4k11110148
add a comment |
add a comment |
There is an object with no property title, because of that you're getting that error. It's something like:
undefined.toLowercase()
^
You can add a checking part on note.title as follow:
note.title && (note.title.toLowercase() === .........)
^
add a comment |
There is an object with no property title, because of that you're getting that error. It's something like:
undefined.toLowercase()
^
You can add a checking part on note.title as follow:
note.title && (note.title.toLowercase() === .........)
^
add a comment |
There is an object with no property title, because of that you're getting that error. It's something like:
undefined.toLowercase()
^
You can add a checking part on note.title as follow:
note.title && (note.title.toLowercase() === .........)
^
There is an object with no property title, because of that you're getting that error. It's something like:
undefined.toLowercase()
^
You can add a checking part on note.title as follow:
note.title && (note.title.toLowercase() === .........)
^
answered Nov 11 at 15:54
Ele
22.7k42044
22.7k42044
add a comment |
add a comment |
You need to provide null check before converting tilte and body to lowercase.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)add a comment |
You need to provide null check before converting tilte and body to lowercase.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)add a comment |
You need to provide null check before converting tilte and body to lowercase.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)You need to provide null check before converting tilte and body to lowercase.
let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)let notes = [,
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
let filteredNotes = notes.filter(function (note, index)
let findFileredTitle = '';
if(note.title)
findFileredTitle = note.title.toLowerCase().includes('ne')
let findFileredBody = '';
if(note.body)
findFileredBody = note.body.toLowerCase().includes('ne');
return findFileredTitle )
console.log(filteredNotes)answered Nov 11 at 15:59
Vikash.777
545316
545316
add a comment |
add a comment |
Update your filter method to check if key exists then going for match other return false.
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title && note.title.toLowerCase().includes('ne')
let findFileredBody = note.body && note.body.toLowerCase().includes('ne')
return findFileredTitle );
add a comment |
Update your filter method to check if key exists then going for match other return false.
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title && note.title.toLowerCase().includes('ne')
let findFileredBody = note.body && note.body.toLowerCase().includes('ne')
return findFileredTitle );
add a comment |
Update your filter method to check if key exists then going for match other return false.
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title && note.title.toLowerCase().includes('ne')
let findFileredBody = note.body && note.body.toLowerCase().includes('ne')
return findFileredTitle );
Update your filter method to check if key exists then going for match other return false.
let filteredNotes = notes.filter( function (note, index)
let findFileredTitle = note.title && note.title.toLowerCase().includes('ne')
let findFileredBody = note.body && note.body.toLowerCase().includes('ne')
return findFileredTitle );
answered Nov 11 at 16:03
front_end_dev
1,3151511
1,3151511
add a comment |
add a comment |
Remove An empty '' object from array , note.title is null/Empty so it return error
let notes = [
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
add a comment |
Remove An empty '' object from array , note.title is null/Empty so it return error
let notes = [
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
add a comment |
Remove An empty '' object from array , note.title is null/Empty so it return error
let notes = [
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
Remove An empty '' object from array , note.title is null/Empty so it return error
let notes = [
title: 'My next trip',
body: 'I would like to go to Spain'
,
title: 'Habits to work on',
body: 'Exercise. Eating a bit better'
,
title: 'Office modification',
body: 'Get a new seat'
]
edited Nov 11 at 16:43
Mark Amery
59.6k30237285
59.6k30237285
answered Nov 11 at 16:02
Mustafa Kunwa
1
1
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%2f53250442%2fjavascript-cannot-read-property-tolowercase-of-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
3
Please do not use pictures of code, it can easily be copy and pasted into the question itself and formatted. It is much easier for users to work with than an image.
– Patrick Evans
Nov 11 at 15:52
See meta.stackoverflow.com/questions/285551/…
– Codo
Nov 11 at 15:53