JavaScript - Cannot read property 'toLowerCase' of undefined










1














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)












share|improve this question



















  • 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















1














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)












share|improve this question



















  • 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













1












1








1







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)












share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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












5 Answers
5






active

oldest

votes


















2














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.






share|improve this answer




























    1














    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() === .........)
    ^





    share|improve this answer




























      0














      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)








      share|improve this answer




























        0














        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 );





        share|improve this answer




























          0














          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'
          ]





          share|improve this answer






















            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
            );



            );













            draft saved

            draft discarded


















            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









            2














            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.






            share|improve this answer

























              2














              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.






              share|improve this answer























                2












                2








                2






                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 11 at 15:58









                Codo

                50.4k11110148




                50.4k11110148























                    1














                    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() === .........)
                    ^





                    share|improve this answer

























                      1














                      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() === .........)
                      ^





                      share|improve this answer























                        1












                        1








                        1






                        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() === .........)
                        ^





                        share|improve this answer












                        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() === .........)
                        ^






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 11 at 15:54









                        Ele

                        22.7k42044




                        22.7k42044





















                            0














                            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)








                            share|improve this answer

























                              0














                              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)








                              share|improve this answer























                                0












                                0








                                0






                                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)








                                share|improve this answer












                                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)






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Nov 11 at 15:59









                                Vikash.777

                                545316




                                545316





















                                    0














                                    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 );





                                    share|improve this answer

























                                      0














                                      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 );





                                      share|improve this answer























                                        0












                                        0








                                        0






                                        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 );





                                        share|improve this answer












                                        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 );






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 11 at 16:03









                                        front_end_dev

                                        1,3151511




                                        1,3151511





















                                            0














                                            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'
                                            ]





                                            share|improve this answer



























                                              0














                                              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'
                                              ]





                                              share|improve this answer

























                                                0












                                                0








                                                0






                                                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'
                                                ]





                                                share|improve this answer














                                                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'
                                                ]






                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited Nov 11 at 16:43









                                                Mark Amery

                                                59.6k30237285




                                                59.6k30237285










                                                answered Nov 11 at 16:02









                                                Mustafa Kunwa

                                                1




                                                1



























                                                    draft saved

                                                    draft discarded
















































                                                    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.




                                                    draft saved


                                                    draft discarded














                                                    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





















































                                                    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







                                                    Popular posts from this blog

                                                    Kleinkühnau

                                                    Makov (Slowakei)

                                                    Deutsches Schauspielhaus